Author: ceki Date: Sun Aug 28 16:14:33 2005 New Revision: 221 Added: nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java nlog4j/trunk/src/java/org/slf4j/IMarkerFactory.java nlog4j/trunk/src/java/org/slf4j/Marker.java nlog4j/trunk/src/java/org/slf4j/impl/BasicMarker.java nlog4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java nlog4j/trunk/src/java/org/slf4j/impl/SimpleLoggerFactory.java nlog4j/trunk/src/java/org/slf4j/impl/StaticBinder.java nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java nlog4j/trunk/src/java/org/slf4j/impl/Util.java nlog4j/trunk/src/java/org/slf4j/spi/ nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java Modified: nlog4j/trunk/src/java/org/slf4j/Logger.java nlog4j/trunk/src/java/org/slf4j/LoggerFactory.java nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java Log: Sync with SLF4J 1.0-beta7
Added: nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j; + + +/** + * <code>ILoggerFactory</code> instances manufacture [EMAIL PROTECTED] Logger} + * instances by name. + * + * <p>Most users retreive [EMAIL PROTECTED] Logger} instances through the static + * [EMAIL PROTECTED] LoggerFactory#getLogger} mehtod. An instance of of this + * interface is bound internally with [EMAIL PROTECTED] LoggerFactory} class at + * compile time. Only developers of SLF4J conformant logging systems + * need to worry about this interface. + * + * <p>See the section <a href="http://slf4j.org/faq.html#3">Implementing + * the SLF4J API</a> in the FAQ for details on how to make your logging + * system conform to SLF4J. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public interface ILoggerFactory { + + /** + * Return an appropriate [EMAIL PROTECTED] Logger} instance as specified by the + * <code>name</code> parameter. + * + * <p>Null-valued name arguments are considered invalid. + * + * <p>Certain extremely simple logging systems, e.g. NOP, may always + * return the same logger instance regardless of the requested name. + * + * @param name the name of the Logger to return + */ + public Logger getLogger(String name); +} Added: nlog4j/trunk/src/java/org/slf4j/IMarkerFactory.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/IMarkerFactory.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j; + + +/** + * Implementaitons of this interface are used to manufacture [EMAIL PROTECTED] Marker} + * instances. + * + * <p>See the section <a href="http://slf4j.org/faq.html#3">Implementing + * the SLF4J API</a> in the FAQ for details on how to make your logging + * system conform to SLF4J. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public interface IMarkerFactory { + + /** + * Manufacture a [EMAIL PROTECTED] Marker} instance by name. If the instance has been + * created earlier, return the previously created instance. + * + * <p>Null name values are not allowed. + * + * @param name the name of the marker to be created, null value is + * not allowed. + * + * @return a Marker instance + */ + Marker getMarker(String name); +} Modified: nlog4j/trunk/src/java/org/slf4j/Logger.java ============================================================================== --- nlog4j/trunk/src/java/org/slf4j/Logger.java (original) +++ nlog4j/trunk/src/java/org/slf4j/Logger.java Sun Aug 28 16:14:33 2005 @@ -226,7 +226,7 @@ public void info(Marker marker, String format, Object arg); /** - * This method is similar to [EMAIL PROTECTED] #debug(String, Object, Object)} + * This method is similar to [EMAIL PROTECTED] #info(String, Object, Object)} * method except that the marker data is also taken into * consideration. * @@ -323,7 +323,7 @@ public void warn(Marker marker, String format, Object arg); /** - * This method is similar to [EMAIL PROTECTED] #debug(String, Object, Object)} + * This method is similar to [EMAIL PROTECTED] #warn(String, Object, Object)} * method except that the marker data is also taken into * consideration. * @@ -422,7 +422,7 @@ public void error(Marker marker, String format, Object arg); /** - * This method is similar to [EMAIL PROTECTED] #debug(String, Object, Object)} + * This method is similar to [EMAIL PROTECTED] #error(String, Object, Object)} * method except that the marker data is also taken into * consideration. * Modified: nlog4j/trunk/src/java/org/slf4j/LoggerFactory.java ============================================================================== --- nlog4j/trunk/src/java/org/slf4j/LoggerFactory.java (original) +++ nlog4j/trunk/src/java/org/slf4j/LoggerFactory.java Sun Aug 28 16:14:33 2005 @@ -1,5 +1,6 @@ /* * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch * * All rights reserved. * @@ -31,6 +32,9 @@ */ package org.slf4j; +import org.slf4j.impl.SystemPropBinder; +import org.slf4j.impl.Util; + // WARNING // WARNING Modifications MUST be made to the original file found at // WARNING $SLF4J_HOME/src/filtered-java/org/slf4j/LoggerFactory.java @@ -52,6 +56,8 @@ * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> */ public final class LoggerFactory { + + static StaticBinder staticBinder = new StaticBinder(); static ILoggerFactory loggerFactory; // private constructor prevents instantiation @@ -63,65 +69,26 @@ // $SLF4J_HOME/src/filtered-java/org/slf4j/ // static { - String loggerFactoryClassStr = "org.slf4j.impl.Log4jLoggerFactory"; - System.out.println("SLF4J built for " + loggerFactoryClassStr); + + loggerFactory = new SystemPropBinder().getLoggerFactory(); - loggerFactory = getFactoryFromSystemProperties(); - - // if could not get an adapter from the system properties, bind statically + // if could get an adapter from the system properties, bind dynamically if (loggerFactory != null) { System.out.println("However, SLF4J will use ["+loggerFactory.getClass().getName() + "] adapter factory from system properties."); } else { - try { - loggerFactory = new org.slf4j.impl.Log4jLoggerFactory(); + try { // otherwise bind statically + loggerFactory = staticBinder.getLoggerFactory(); } catch (Exception e) { // we should never get here Util.reportFailure( - "Could not instantiate instance of class [" + loggerFactoryClassStr + "]", + "Could not instantiate instance of class [" + staticBinder.getLoggerFactoryClassStr() + "]", e); } } } - /** - * Fetch the appropriate ILoggerFactory as intructed by the system propties. - * - * @return The appropriate ILoggerFactory instance as directed from the - * system properties - */ - private static ILoggerFactory getFactoryFromSystemProperties() { - String factoryFactoryClassName = null; - try { - factoryFactoryClassName = System.getProperty(Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME); - if (factoryFactoryClassName == null) { - return null; - } - - Class factoryFactoryClass = Class.forName(factoryFactoryClassName); - Class[] EMPTY_CLASS_ARRAY = { }; - java.lang.reflect.Method factoryFactoryMethod = - factoryFactoryClass.getDeclaredMethod( - Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME, EMPTY_CLASS_ARRAY); - ILoggerFactory loggerFactory = - (ILoggerFactory) factoryFactoryMethod.invoke(null, null); - return loggerFactory; - } catch (Throwable t) { - if (factoryFactoryClassName == null) { - Util.reportFailure( - "Failed to fetch " + Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME - + " system property.", t); - } else { - Util.reportFailure( - "Failed to fetch ILoggerFactory instnace using the " - + factoryFactoryClassName + " class.", t); - } - } - - // we could not get an adapter - return null; - } /** * Return a logger named according to the name parameter using the @@ -157,4 +124,8 @@ return loggerFactory; } + public static StaticBinder getStaticBinder() { + return staticBinder; + } + } Added: nlog4j/trunk/src/java/org/slf4j/Marker.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/Marker.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j; + +import java.util.Iterator; + +/** + * Markers are named objects used to enrich log statements. Conforming + * logging system Implementations of SLF4J determine how information + * conveyed by markers are used, if at all. In particular, many + * conformant logging systems may ignore marker data. + * + * <p>Markers can contain child markers, which in turn can contain children + * of their own. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public interface Marker { + + /** + * Get the name of this Marker. + * @return name of marker + */ + public String getName(); + + /** + * Add a child Marker to this Marker. + * @param child a child marker + */ + public void add(Marker child); + + /** + * Remove a child Marker. + * @param child the child Marker to remove + * @return true if child could be found and removed, false otherwise. + */ + public boolean remove(Marker child); + + /** + * Does this marker have children? + * @return true if this marker has children, false otherwise. + */ + public boolean hasChildren(); + + /** + * Returns an Iterator which can be used to iterate over the + * children of this marker. An empty iterator is returned when this + * marker has no children. + * + * @return Iterator over the children of this marker + */ + public Iterator iterator(); + +// void makeImmutable(); +// public boolean isImmutable(); +} Added: nlog4j/trunk/src/java/org/slf4j/impl/BasicMarker.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/BasicMarker.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + +import org.slf4j.Marker; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + + +/** + * An almost trivial implementation of the [EMAIL PROTECTED] Marker} interface. + * + * <p><code>BasicMarker</code> lets users specify marker + * information. However, it does not offer any useful operations on + * that information. + * + * <p>Simple logging systems which ignore marker data, just return + * instances of this class in order to conform to the SLF4J API. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public class BasicMarker implements Marker { + String name; + List children; + + BasicMarker(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public synchronized void add(Marker child) { + if (child == null) { + throw new NullPointerException( + "Null children cannot be added to a Marker."); + } + if (children == null) { + children = new Vector(); + } + children.add(child); + } + + public synchronized boolean hasChildren() { + return ((children != null) && (children.size() > 0)); + } + + public synchronized Iterator iterator() { + if (children != null) { + return children.iterator(); + } else { + return Collections.EMPTY_LIST.iterator(); + } + } + + public synchronized boolean remove(Marker markerToRemove) { + if (children == null) { + return false; + } + + int size = children.size(); + for (int i = 0; i < size; i++) { + Marker m = (Marker) children.get(i); + if( m == markerToRemove) { + return false; + } + } + // could not find markerToRemove + return false; + } +} Added: nlog4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/BasicMarkerFactory.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.IMarkerFactory; +import org.slf4j.Marker; + +/** + * An almost trivial implementation of the [EMAIL PROTECTED] IMarkerFactory} + * interface which creates [EMAIL PROTECTED] BasicMarker} instances. + * + * <p>Simple logging systems can conform to the SLF4J API by binding + * [EMAIL PROTECTED] org.slf4j.MarkerFactory} with an instance of this class. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public class BasicMarkerFactory implements IMarkerFactory { + + Map markerMap = new HashMap(); + + /** + * Regular users should <em>not</em> create + * <code>BasicMarkerFactory</code> instances. <code>Marker</code> + * instances can be obtained using the static [EMAIL PROTECTED] + * org.slf4j.MarkerFactory#getMarker} method. + */ + public BasicMarkerFactory() { + } + + /** + * Manufacture a [EMAIL PROTECTED] BasicMarker} instance by name. If the instance has been + * created earlier, return the previously created instance. + * + * @param name the name of the marker to be created + * @return a Marker instance + */ + public synchronized Marker getMarker(String name) { + if (name == null) { + throw new IllegalArgumentException("Marker name cannot be null"); + } + + Marker marker = (Marker) markerMap.get(name); + if (marker == null) { + marker = new BasicMarker(name); + markerMap.put(name, marker); + } + return marker; + } +} Modified: nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java ============================================================================== --- nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java (original) +++ nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java Sun Aug 28 16:14:33 2005 @@ -39,7 +39,7 @@ * See [EMAIL PROTECTED] #format(String, Object)} and * [EMAIL PROTECTED] #format(String, Object, Object)} for more details. * - * @author Ceki Gülcü + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> */ public class MessageFormatter { static final char DELIM_START = '{'; Added: nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + +import org.slf4j.Logger; +import org.slf4j.ILoggerFactory; + + +/** + * NOPLoggerFactory is an trivial implementation of [EMAIL PROTECTED] + * ILoggerFactory} which always returns the unique instance of + * NOPLogger. + * + * @author Ceki Gulcu + */ +public class NOPLoggerFactory implements ILoggerFactory { + + public NOPLoggerFactory() { + // nothing to do + } + + public Logger getLogger(String name) { + return NOPLogger.NOP_LOGGER; + } + +} Added: nlog4j/trunk/src/java/org/slf4j/impl/SimpleLoggerFactory.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/SimpleLoggerFactory.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.ILoggerFactory; + + +/** + * An implementation of [EMAIL PROTECTED] ILoggerFactory} which always returns + * [EMAIL PROTECTED] SimpleLogger} instances. + * + * @author Ceki Gülcü + */ +public class SimpleLoggerFactory implements ILoggerFactory { + + Map map; + + public SimpleLoggerFactory() { + map = new HashMap(); + } + + + /** + * Return an appropriate [EMAIL PROTECTED] SimpleLogger} instance by name. + */ + public Logger getLogger(String name) { + Logger ulogger = (Logger) map.get(name); + if(ulogger == null) { + ulogger = new SimpleLogger(name); + map.put(name, ulogger); + } + return ulogger; + } +} Added: nlog4j/trunk/src/java/org/slf4j/impl/StaticBinder.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/StaticBinder.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + +import org.slf4j.ILoggerFactory; +import org.slf4j.spi.LoggerFactoryBinder; + +public class StaticBinder implements LoggerFactoryBinder { + + + String loggerFactoryClassStr = Log4jLoggerFactory.class.getName(); + + public ILoggerFactory getLoggerFactory() { + return new Log4jLoggerFactory(); + } + + public String getLoggerFactoryClassStr() { + return loggerFactoryClassStr; + } + +} Added: nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,62 @@ +// TOTO + +package org.slf4j.impl; + +import org.slf4j.Constants; +import org.slf4j.ILoggerFactory; +import org.slf4j.spi.LoggerFactoryBinder; + +/** + * @author ceki + * + * TODO To change the template for this generated type comment go to Window - + * Preferences - Java - Code Style - Code Templates + */ +public class SystemPropBinder implements LoggerFactoryBinder { + String factoryFactoryClassName = null; + + /** + * Fetch the appropriate ILoggerFactory as intructed by the system propties. + * + * @return The appropriate ILoggerFactory instance as directed from the system + * properties + */ + public ILoggerFactory getLoggerFactory() { + + try { + if (getLoggerFactoryClassStr() == null) { + return null; + } + + Class factoryFactoryClass = Class.forName(getLoggerFactoryClassStr()); + Class[] EMPTY_CLASS_ARRAY = {}; + java.lang.reflect.Method factoryFactoryMethod = factoryFactoryClass + .getDeclaredMethod(Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME, + EMPTY_CLASS_ARRAY); + ILoggerFactory loggerFactory = (ILoggerFactory) factoryFactoryMethod + .invoke(null, null); + return loggerFactory; + } catch (Exception e) { + Util.reportFailure("Failed to fetch ILoggerFactory instnace using the " + + factoryFactoryClassName + " class.", e); + + } + + // we could not get an adapter + return null; + } + + public String getLoggerFactoryClassStr() { + if (factoryFactoryClassName == null) { + try { + factoryFactoryClassName = System + .getProperty(Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME); + } catch (Exception e) { + Util.reportFailure("Failed to fetch " + + Constants.LOGGER_FACTORY_FACTORY_METHOD_NAME + + " system property.", e); + } + } + return factoryFactoryClassName; + } +} \ No newline at end of file Added: nlog4j/trunk/src/java/org/slf4j/impl/Util.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/impl/Util.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.impl; + + +/** + * + * An internal utility class. + * + * @author Ceki Gulcu + */ +public class Util { + + static public void reportFailure(String msg, Throwable t) { + System.err.println(msg); + System.err.println("Reported exception follows."); + t.printStackTrace(); + } +} Added: nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java ============================================================================== --- (empty file) +++ nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java Sun Aug 28 16:14:33 2005 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2004-2005 SLF4J.ORG + * Copyright (c) 2004-2005 QOS.ch + * + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY + * SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + * + */ + +package org.slf4j.spi; + +import org.slf4j.ILoggerFactory; + +/** + * An internal interface which helps the static [EMAIL PROTECTED] org.slf4j.LoggerFactory} + * class bind with the appropriate [EMAIL PROTECTED] ILoggerFactory} instance. + * + * @author <a href="http://www.qos.ch/log4j/">Ceki Gülcü</a> + */ +public interface LoggerFactoryBinder { + + /** + * Return the instance of [EMAIL PROTECTED] ILoggerFactory} that + * [EMAIL PROTECTED] org.slf4j.LoggerFactory} class should bind to. + * + * @return the instance of [EMAIL PROTECTED] ILoggerFactory} that + * [EMAIL PROTECTED] org.slf4j.LoggerFactory} class should bind to. + */ + public ILoggerFactory getLoggerFactory(); + + /** + * The String form of the [EMAIL PROTECTED] ILoggerFactory} object that this + * <code>LoggerFactoryBinder</code> instance is <em>intended</em> to return. + * + * <p>This method allows the developer to intterogate this binder's intention + * which may be different from the [EMAIL PROTECTED] ILoggerFactory} instance it is able to + * yields in practice. The discrepency should only occur in case of errors. + * + * @return the class name of the intended [EMAIL PROTECTED] ILoggerFactory} instance + */ + public String getLoggerFactoryClassStr(); +} _______________________________________________ nlog4j-dev mailing list [email protected] http://slf4j.org/mailman/listinfo/nlog4j-dev
