diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..555af6ef --- /dev/null +++ b/pom.xml @@ -0,0 +1,99 @@ + + + 4.0.0 + + org.slf4j + slf4j + 1.1.0 + pom + SLF4J + + + http://www.slf4j.org + + + QOS.ch + http://www.qos.ch + + 2005 + + + slf4j-api + + + + + junit + junit + 3.8.1 + test + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-site-plugin + + + org.apache.maven.plugins + + maven-project-info-reports-plugin + + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + true + + + http://java.sun.com/j2se/1.5.0/docs/api + + + + + + + maven-assembly-plugin + 2.1 + + + + src/main/assembly/source.xml + + + + logback-${project.version} + + false + target/site/dist/ + + + + + + + + + \ No newline at end of file diff --git a/slf4j-api/pom.xml b/slf4j-api/pom.xml new file mode 100644 index 00000000..a75151fb --- /dev/null +++ b/slf4j-api/pom.xml @@ -0,0 +1,78 @@ + + + + org.slf4j + slf4j + 1.1.0 + + + 4.0.0 + + org.slf4j + slf4j-api + ${parent.version} + jar + SLF4J API Module + + http://www.slf4j.org + + + Logback: the generic, reliable, fast and flexible logging library for Java. + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + once + plain + false + + **/AllTest.java + **/PackageTest.java + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + bundle-test-jar + package + + jar + test-jar + + + + + + + + + + + + \ No newline at end of file diff --git a/slf4j-api/src/main/java/org/slf4j/ILoggerFactory.java b/slf4j-api/src/main/java/org/slf4j/ILoggerFactory.java new file mode 100644 index 00000000..0eadac21 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/ILoggerFactory.java @@ -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; + + +/** + * ILoggerFactory instances manufacture {@link Logger} + * instances by name. + * + *

Most users retrieve {@link Logger} instances through the static + * {@link LoggerFactory#getLogger(String)} method. An instance of of this + * interface is bound internally with {@link LoggerFactory} class at + * compile time. Only developers of SLF4J conforming logging systems + * need to worry about this interface. + * + *

See the section Implementing + * the SLF4J API in the FAQ for details on how to make your logging + * system conform to SLF4J. + * + * @author Ceki Gülcü + */ +public interface ILoggerFactory { + + /** + * Return an appropriate {@link Logger} instance as specified by the + * name parameter. + * + *

Null-valued name arguments are considered invalid. + * + *

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); +} diff --git a/slf4j-api/src/main/java/org/slf4j/IMarkerFactory.java b/slf4j-api/src/main/java/org/slf4j/IMarkerFactory.java new file mode 100644 index 00000000..ce2b5cfc --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/IMarkerFactory.java @@ -0,0 +1,68 @@ +/* + * 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 {@link Marker} + * instances. + * + *

See the section Implementing + * the SLF4J API in the FAQ for details on how to make your logging + * system conform to SLF4J. + * + * @author Ceki Gülcü + */ +public interface IMarkerFactory { + + /** + * Manufacture a {@link Marker} instance by name. If the instance has been + * created earlier, return the previously created instance. + * + *

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); + + /** + * Checks if the marker with the name already exists. If name is null, then false + * is returned. + * + * @return true id the marker exists, false otherwise. + */ + boolean exists(String name); +} diff --git a/slf4j-api/src/main/java/org/slf4j/Logger.java b/slf4j-api/src/main/java/org/slf4j/Logger.java new file mode 100644 index 00000000..62dec091 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/Logger.java @@ -0,0 +1,546 @@ +/* + * 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; + +/** + * + * The main user interface to logging. It is expected that logging + * takes place through concrete implementations of this interface. + * + * @author Ceki Gülcü + */ +public interface Logger { + + + /** + * Return the name of this Logger instance. + */ + public String getName(); + + /** + * Is the logger instance enabled for the DEBUG level? + * @return True if this Logger is enabled for the DEBUG level, + * false otherwise. + */ + public boolean isDebugEnabled(); + + /** + * Log a message at the DEBUG level. + * + * @param msg the message string to be logged + */ + public void debug(String msg); + + + /** + * Log a message at the DEBUG level according to the specified format + * and argument. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the DEBUG level.

+ * + * @param format the format string + * @param arg the argument + */ + public void debug(String format, Object arg); + + + + /** + * Log a message at the DEBUG level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the DEBUG level.

+ * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void debug(String format, Object arg1, Object arg2); + + /** + * Log a message at the DEBUG level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the DEBUG level.

+ * + * @param format the format string + * @param argArray an array of arguments + */ + public void debug(String format, Object[] argArray); + + /** + * Log an exception (throwable) at the DEBUG level with an + * accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void debug(String msg, Throwable t); + + + /** + * Similar to {@link #isDebugEnabled()} method except that the + * marker data is also taken into account. + * + * @param marker The marker data to take into consideration + */ + public boolean isDebugEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the DEBUG level. + * + * @param marker the marker data specific to this log statement + * @param msg the message string to be logged + */ + public void debug(Marker marker, String msg); + + /** + * This method is similar to {@link #debug(String, Object)} method except that the + * marker data is also taken into consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public void debug(Marker marker, String format, Object arg); + + + /** + * This method is similar to {@link #debug(String, Object, Object)} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void debug(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #debug(String, Object[])} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param argArray an array of arguments + */ + public void debug(Marker marker, String format, Object[] argArray); + + + /** + * This method is similar to {@link #debug(String, Throwable)} method except that the + * marker data is also taken into consideration. + * + * @param marker the marker data specific to this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void debug(Marker marker, String msg, Throwable t); + + + /** + * Is the logger instance enabled for the INFO level? + * @return True if this Logger is enabled for the INFO level, + * false otherwise. + */ + public boolean isInfoEnabled(); + + + /** + * Log a message at the INFO level. + * + * @param msg the message string to be logged + */ + public void info(String msg); + + + /** + * Log a message at the INFO level according to the specified format + * and argument. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the INFO level.

+ * + * @param format the format string + * @param arg the argument + */ + public void info(String format, Object arg); + + + /** + * Log a message at the INFO level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the INFO level.

+ * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void info(String format, Object arg1, Object arg2); + + /** + * Log a message at the INFO level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the INFO level.

+ * + * @param format the format string + * @param argArray an array of arguments + */ + public void info(String format, Object[] argArray); + + /** + * Log an exception (throwable) at the INFO level with an + * accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void info(String msg, Throwable t); + + /** + * Similar to {@link #isInfoEnabled()} method except that the marker + * data is also taken into consideration. + * + * @param marker The marker data to take into consideration + */ + public boolean isInfoEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the INFO level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public void info(Marker marker, String msg); + + /** + * This method is similar to {@link #info(String, Object)} method except that the + * marker data is also taken into consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public void info(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #info(String, Object, Object)} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void info(Marker marker, String format, Object arg1, Object arg2); + + + /** + * This method is similar to {@link #info(String, Object[])} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param argArray an array of arguments + */ + public void info(Marker marker, String format, Object[] argArray); + + + /** + * This method is similar to {@link #info(String, Throwable)} method + * except that the marker data is also taken into consideration. + * + * @param marker the marker data for this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void info(Marker marker, String msg, Throwable t); + + + /** + * Is the logger instance enabled for the WARN level? + * @return True if this Logger is enabled for the WARN level, + * false otherwise. + */ + public boolean isWarnEnabled(); + + /** + * Log a message at the WARN level. + * + * @param msg the message string to be logged + */ + public void warn(String msg); + + /** + * Log a message at the WARN level according to the specified format + * and argument. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the WARN level.

+ * + * @param format the format string + * @param arg the argument + */ + public void warn(String format, Object arg); + + + /** + * Log a message at the WARN level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the WARN level.

+ * + * @param format the format string + * @param argArray an array of arguments + */ + public void warn(String format, Object[] argArray); + + /** + * Log a message at the WARN level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the WARN level.

+ * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void warn(String format, Object arg1, Object arg2); + + /** + * Log an exception (throwable) at the WARN level with an + * accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void warn(String msg, Throwable t); + + + /** + * Similar to {@link #isWarnEnabled()} method except that the marker + * data is also taken into consideration. + * + * @param marker The marker data to take into consideration + */ + public boolean isWarnEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the WARN level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public void warn(Marker marker, String msg); + + /** + * This method is similar to {@link #warn(String, Object)} method except that the + * marker data is also taken into consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public void warn(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #warn(String, Object, Object)} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void warn(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #warn(String, Object[])} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param argArray an array of arguments + */ + public void warn(Marker marker, String format, Object[] argArray); + + + /** + * This method is similar to {@link #warn(String, Throwable)} method + * except that the marker data is also taken into consideration. + * + * @param marker the marker data for this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void warn(Marker marker, String msg, Throwable t); + + + /** + * Is the logger instance enabled for the ERROR level? + * @return True if this Logger is enabled for the ERROR level, + * false otherwise. + */ + public boolean isErrorEnabled(); + + /** + * Log a message at the ERROR level. + * + * @param msg the message string to be logged + */ + public void error(String msg); + + /** + * Log a message at the ERROR level according to the specified format + * and argument. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the ERROR level.

+ * + * @param format the format string + * @param arg the argument + */ + public void error(String format, Object arg); + + /** + * Log a message at the ERROR level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the ERROR level.

+ * + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void error(String format, Object arg1, Object arg2); + + /** + * Log a message at the ERROR level according to the specified format + * and arguments. + * + *

This form avoids superfluous object creation when the logger + * is disabled for the ERROR level.

+ * + * @param format the format string + * @param argArray an array of arguments + */ + public void error(String format, Object[] argArray); + + /** + * Log an exception (throwable) at the ERROR level with an + * accompanying message. + * + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void error(String msg, Throwable t); + + + /** + * Similar to {@link #isErrorEnabled()} method except that the + * marker data is also taken into consideration. + * + * @param marker The marker data to take into consideration + */ + public boolean isErrorEnabled(Marker marker); + + /** + * Log a message with the specific Marker at the ERROR level. + * + * @param marker The marker specific to this log statement + * @param msg the message string to be logged + */ + public void error(Marker marker, String msg); + + /** + * This method is similar to {@link #error(String, Object)} method except that the + * marker data is also taken into consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg the argument + */ + public void error(Marker marker, String format, Object arg); + + /** + * This method is similar to {@link #error(String, Object, Object)} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param arg1 the first argument + * @param arg2 the second argument + */ + public void error(Marker marker, String format, Object arg1, Object arg2); + + /** + * This method is similar to {@link #error(String, Object[])} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param format the format string + * @param argArray an array of arguments + */ + public void error(Marker marker, String format, Object[] argArray); + + + /** + * This method is similar to {@link #error(String, Throwable)} + * method except that the marker data is also taken into + * consideration. + * + * @param marker the marker data specific to this log statement + * @param msg the message accompanying the exception + * @param t the exception (throwable) to log + */ + public void error(Marker marker, String msg, Throwable t); + +} diff --git a/slf4j-api/src/main/java/org/slf4j/Marker.java b/slf4j-api/src/main/java/org/slf4j/Marker.java new file mode 100644 index 00000000..99393a63 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/Marker.java @@ -0,0 +1,120 @@ +/* + * 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 + * conforming logging systems ignore marker data. + * + *

Markers can contain child markers, which in turn can contain children + * of their own. + * + * @author Ceki Gülcü + */ +public interface Marker { + + /** + * This constant represents any marker, including a null marker. + */ + public static final String ANY_MARKER = "*"; + + /** + * This constant represents any non-null marker. + */ + public static final String ANY_NON_NULL_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(); + + /** + * Does this marker contain the 'other' marker? Marker A is defined to + * contain marker B, if A == B or if B is a child of A. + * + * @param other The marker to test for inclusion. + * @throws IllegalArgumentException if 'other' is null + * @return Whether this marker contains the other marker. + */ + public boolean contains(Marker other); + + + + /** + * Does this marker contain the marker named 'name'? + * + * If 'name' is null the returned value is always false. + * + * @param other The marker to test for inclusion. + * @return Whether this marker contains the other marker. + */ + public boolean contains(String name); + +// void makeImmutable(); +// public boolean isImmutable(); +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/BasicMarker.java b/slf4j-api/src/main/java/org/slf4j/impl/BasicMarker.java new file mode 100644 index 00000000..fbc15075 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/BasicMarker.java @@ -0,0 +1,142 @@ +/* + * 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.IMarkerFactory; +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 {@link Marker} interface. + * + *

BasicMarker lets users specify marker + * information. However, it does not offer any useful operations on + * that information. + * + *

Simple logging systems which ignore marker data, just return + * instances of this class in order to conform to the SLF4J API. + * + * @author Ceki Gülcü + */ +public class BasicMarker implements Marker { + final String name; + List children; + final IMarkerFactory factory; + + BasicMarker(String name, IMarkerFactory factory) { + this.name = name; + this.factory = factory; + } + + 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; + } + + public boolean contains(Marker other) { + if(other == null) { + throw new IllegalArgumentException("Other cannot be null"); + } + + if(this == other) { + return true; + } + + if (hasChildren()) { + for(int i = 0; i < children.size(); i++) { + Marker child = (Marker) children.get(i); + if(child.contains(other)) { + return true; + } + } + } + return false; + } + + public boolean contains(String name) { + if(name == null) { + return false; + } + if(factory.exists(name)) { + Marker other = factory.getMarker(name); + return contains(other); + } else { + return false; + } + } + +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/BasicMarkerFactory.java b/slf4j-api/src/main/java/org/slf4j/impl/BasicMarkerFactory.java new file mode 100644 index 00000000..d06b92c9 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/BasicMarkerFactory.java @@ -0,0 +1,94 @@ +/* + * 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 {@link IMarkerFactory} + * interface which creates {@link BasicMarker} instances. + * + *

Simple logging systems can conform to the SLF4J API by binding + * {@link org.slf4j.MarkerFactory} with an instance of this class. + * + * @author Ceki Gülcü + */ +public class BasicMarkerFactory implements IMarkerFactory { + + Map markerMap = new HashMap(); + + /** + * Regular users should not create + * BasicMarkerFactory instances. Marker + * instances can be obtained using the static {@link + * org.slf4j.MarkerFactory#getMarker} method. + */ + public BasicMarkerFactory() { + } + + /** + * Manufacture a {@link 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, this); + markerMap.put(name, marker); + } + return marker; + } + + /** + * Does the name marked already exist? + */ + public synchronized boolean exists(String name) { + if (name == null) { + return false; + } + return markerMap.containsKey(name); + } + +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/MarkerIgnoringBase.java b/slf4j-api/src/main/java/org/slf4j/impl/MarkerIgnoringBase.java new file mode 100644 index 00000000..d9b8fff5 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/MarkerIgnoringBase.java @@ -0,0 +1,147 @@ +/* + * 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.Marker; + + +/** + * This class serves as base for adapters or native implementations of logging systems + * lacking Marker support. In this implementation, methods taking marker data + * simply invoke the corresponding method without the Marker argument, discarding + * any marker data passed as argument. + * + * @author Ceki Gulcu + */ +public abstract class MarkerIgnoringBase implements Logger { + + public boolean isDebugEnabled(Marker marker) { + return isDebugEnabled(); + } + + public void debug(Marker marker, String msg) { + debug(msg); + } + + public void debug(Marker marker, String format, Object arg) { + debug(format, arg); + } + + public void debug(Marker marker, String format, Object arg1, Object arg2) { + debug(format, arg1, arg2); + } + + public void debug(Marker marker, String format, Object[] argArray) { + debug(format, argArray); + } + + public void debug(Marker marker, String msg, Throwable t) { + debug(msg, t); + } + + public boolean isInfoEnabled(Marker marker) { + return isInfoEnabled(); + } + + public void info(Marker marker, String msg) { + info(msg); + } + + public void info(Marker marker, String format, Object arg) { + info(format, arg); + } + + public void info(Marker marker, String format, Object arg1, Object arg2) { + info(format, arg1, arg2); + } + + public void info(Marker marker, String format, Object[] argArray) { + info(format, argArray); + } + + public void info(Marker marker, String msg, Throwable t) { + info(msg, t); + } + + public boolean isWarnEnabled(Marker marker) { + return isWarnEnabled(); + } + + public void warn(Marker marker, String msg) { + warn(msg); + } + + public void warn(Marker marker, String format, Object arg) { + warn(format, arg); + } + + public void warn(Marker marker, String format, Object arg1, Object arg2) { + warn(format, arg1, arg2); + } + + public void warn(Marker marker, String format, Object[] argArray) { + warn(format, argArray); + } + + public void warn(Marker marker, String msg, Throwable t) { + warn(msg, t); + } + + + public boolean isErrorEnabled(Marker marker) { + return isErrorEnabled(); + } + + public void error(Marker marker, String msg) { + error(msg); + } + + public void error(Marker marker, String format, Object arg) { + error(format, arg); + } + + public void error(Marker marker, String format, Object arg1, Object arg2) { + error(format, arg1, arg2); + } + + public void error(Marker marker, String format, Object[] argArray) { + error(format, argArray); + } + + public void error(Marker marker, String msg, Throwable t) { + error(msg, t); + } + +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/MessageFormatter.java b/slf4j-api/src/main/java/org/slf4j/impl/MessageFormatter.java new file mode 100644 index 00000000..12a49b86 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/MessageFormatter.java @@ -0,0 +1,159 @@ +/* + * 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; + + +/** + * Formats messages according to very simple substitution rules. Substitutions can be + * made 1, 2 or more arguments. + *

+ * For example, + *

MessageFormatter.format("Hi {}.", "there");
will + * return the string "Hi there.". + *

+ * The {} pair is called the formatting anchor. It serves to designate the + * location where arguments need to be substituted within the message pattern. + *

+ * In the rare case where you need to place the '{' or '}' in the message pattern + * itself but do not want them to be interpreted as a formatting anchors, you can + * espace the '{' character with '\', that is the backslash character. Only the + * '{' character should be escaped. There is no need to escape the '}' character. + * For example,

MessageFormatter.format("File name is \\{{}}.", "App folder.zip");
+ * will return the string "File name is {App folder.zip}.". + * + * See {@link #format(String, Object)}, {@link #format(String, Object, Object)} + * and {@link #arrayFormat(String, Object[])} methods for more details. + * + * @author Ceki Gülcü + */ +public class MessageFormatter { + static final char DELIM_START = '{'; + static final char DELIM_STOP = '}'; + + /** + * Performs single argument substitution for the 'messagePattern' passed as + * parameter. + *

+ * For example,

MessageFormatter.format("Hi {}.", "there");
will + * return the string "Hi there.". + *

+ * @param messagePattern The message pattern which will be parsed and formatted + * @param argument The argument to be substituted in place of the formatting anchor + * @return The formatted message + */ + public static String format(String messagePattern, Object arg) { + return arrayFormat(messagePattern, new Object[] {arg}); + } + + /** + * + * Performs a two argument substitution for the 'messagePattern' passed as + * parameter. + *

+ * For example, + *

MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");
will + * return the string "Hi Alice. My name is Bob.". + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param arg1 The argument to be substituted in place of the first formatting anchor + * @param arg2 The argument to be substituted in place of the second formatting anchor + * @return The formatted message + */ + public static String format(String messagePattern, Object arg1, Object arg2) { + return arrayFormat(messagePattern, new Object[] {arg1, arg2}); + } + + /** + * Same principle as the {@link #format(String, Object)} and + * {@link #format(String, Object, Object)} methods except that + * any number of arguments can be passed in an array. + * + * @param messagePattern The message pattern which will be parsed and formatted + * @param argArray An array of arguments to be substituted in place of formatting anchors + * @return The formatted message + */ + public static String arrayFormat(String messagePattern, Object[] argArray) { + if(messagePattern == null) { + return null; + } + int i = 0; + int len = messagePattern.length(); + int j = messagePattern.indexOf(DELIM_START); + + + + StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50); + + for (int L = 0; L < argArray.length; L++) { + + char escape = 'x'; + + j = messagePattern.indexOf(DELIM_START, i); + + if (j == -1 || (j+1 == len)) { + // no more variables + if (i == 0) { // this is a simple string + return messagePattern; + } else { // add the tail string which contains no variables and return the result. + sbuf.append(messagePattern.substring(i, messagePattern.length())); + return sbuf.toString(); + } + } else { + char delimStop = messagePattern.charAt(j + 1); + if (j > 0) { + escape = messagePattern.charAt(j - 1); + } + + if(escape == '\\') { + L--; // DELIM_START was escaped, thus should not be incremented + sbuf.append(messagePattern.substring(i, j-1)); + sbuf.append(DELIM_START); + i = j + 1; + } else if ((delimStop != DELIM_STOP)) { + // invalid DELIM_START/DELIM_STOP pair + sbuf.append(messagePattern.substring(i, messagePattern.length())); + return sbuf.toString(); + } else { + // normal case + sbuf.append(messagePattern.substring(i, j)); + sbuf.append(argArray[L]); + i = j + 2; + } + } + } + // append the characters following the second {} pair. + sbuf.append(messagePattern.substring(i, messagePattern.length())); + return sbuf.toString(); + } +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/Util.java b/slf4j-api/src/main/java/org/slf4j/impl/Util.java new file mode 100644 index 00000000..10dff936 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/Util.java @@ -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 Gülcü + */ +public class Util { + + static final public void reportFailure(String msg, Throwable t) { + System.err.println(msg); + System.err.println("Reported exception:"); + t.printStackTrace(); + } +} diff --git a/slf4j-api/src/main/java/org/slf4j/impl/package.html b/slf4j-api/src/main/java/org/slf4j/impl/package.html new file mode 100644 index 00000000..f4311e30 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/impl/package.html @@ -0,0 +1,17 @@ + + + + + + + + + + + +

Implementations of core logging interfaces defined in the {@link + org.slf4j} package.

+ +
+ + diff --git a/slf4j-api/src/main/java/org/slf4j/package.html b/slf4j-api/src/main/java/org/slf4j/package.html new file mode 100644 index 00000000..4f407d07 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/package.html @@ -0,0 +1,16 @@ + + + + + + + + + + + +

Core logging interfaces.

+ +
+ + diff --git a/slf4j-api/src/main/java/org/slf4j/spi/LoggerFactoryBinder.java b/slf4j-api/src/main/java/org/slf4j/spi/LoggerFactoryBinder.java new file mode 100644 index 00000000..9abedc52 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/spi/LoggerFactoryBinder.java @@ -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 {@link org.slf4j.LoggerFactory} + * class bind with the appropriate {@link ILoggerFactory} instance. + * + * @author Ceki Gülcü + */ +public interface LoggerFactoryBinder { + + /** + * Return the instance of {@link ILoggerFactory} that + * {@link org.slf4j.LoggerFactory} class should bind to. + * + * @return the instance of {@link ILoggerFactory} that + * {@link org.slf4j.LoggerFactory} class should bind to. + */ + public ILoggerFactory getLoggerFactory(); + + /** + * The String form of the {@link ILoggerFactory} object that this + * LoggerFactoryBinder instance is intended to return. + * + *

This method allows the developer to intterogate this binder's intention + * which may be different from the {@link ILoggerFactory} instance it is able to + * yield in practice. The discrepency should only occur in case of errors. + * + * @return the class name of the intended {@link ILoggerFactory} instance + */ + public String getLoggerFactoryClassStr(); +} diff --git a/slf4j-api/src/main/java/org/slf4j/spi/MarkerFactoryBinder.java b/slf4j-api/src/main/java/org/slf4j/spi/MarkerFactoryBinder.java new file mode 100644 index 00000000..fc01d178 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/spi/MarkerFactoryBinder.java @@ -0,0 +1,67 @@ +/* + * 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.IMarkerFactory; + + +/** + * An internal interface which helps the static {@link org.slf4j.MarkerFactory} + * class bind with the appropriate {@link IMarkerFactory} instance. + * + * @author Ceki Gülcü + */ +public interface MarkerFactoryBinder { + + /** + * Return the instance of {@link IMarkerFactory} that + * {@link org.slf4j.MarkerFactory} class should bind to. + * + * @return the instance of {@link IMarkerFactory} that + * {@link org.slf4j.MarkerFactory} class should bind to. + */ + public IMarkerFactory getMarkerFactory(); + + /** + * The String form of the {@link IMarkerFactory} object that this + * MarkerFactoryBinder instance is intended to return. + * + *

This method allows the developer to intterogate this binder's intention + * which may be different from the {@link IMarkerFactory} instance it is able to + * return. Such a discrepency should only occur in case of errors. + * + * @return the class name of the intended {@link IMarkerFactory} instance + */ + public String getMarkerFactoryClassStr(); +} diff --git a/slf4j-api/src/main/java/org/slf4j/spi/package.html b/slf4j-api/src/main/java/org/slf4j/spi/package.html new file mode 100644 index 00000000..242f19d5 --- /dev/null +++ b/slf4j-api/src/main/java/org/slf4j/spi/package.html @@ -0,0 +1,8 @@ + + + + +Classes and interfaces which are internal to SLF4J. Under most +circumstances SLF4J users should be oblivious even to the existence of +this package. + \ No newline at end of file diff --git a/slf4j-api/src/test/java/org/slf4j/AllTest.java b/slf4j-api/src/test/java/org/slf4j/AllTest.java new file mode 100644 index 00000000..2f430be5 --- /dev/null +++ b/slf4j-api/src/test/java/org/slf4j/AllTest.java @@ -0,0 +1,20 @@ +// TOTO + +package org.slf4j; + +import org.slf4j.impl.MessageFormatterTest; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AllTest extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTestSuite(MessageFormatterTest.class); + suite.addTestSuite(BasicMarkerTest.class); + return suite; + } + +} diff --git a/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java b/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java new file mode 100644 index 00000000..bb72f5cb --- /dev/null +++ b/slf4j-api/src/test/java/org/slf4j/BasicMarkerTest.java @@ -0,0 +1,114 @@ +/* + * 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 junit.framework.TestCase; + +import org.slf4j.impl.BasicMarkerFactory; + + +/** + * @author ceki + */ +public class BasicMarkerTest extends TestCase { + static final String BLUE_STR = "BLUE"; + static final String RED_STR = "RED"; + static final String GREEN_STR = "GREEN"; + static final String COMP_STR = "COMP"; + static final String MULTI_COMP_STR = "MULTI_COMP"; + + final IMarkerFactory factory; + final Marker blue; + final Marker red; + final Marker green; + final Marker comp; + final Marker multiComp; + + public BasicMarkerTest() { + factory = new BasicMarkerFactory(); + + blue = factory.getMarker(BLUE_STR); + red = factory.getMarker(RED_STR); + green = factory.getMarker(GREEN_STR); + comp = factory.getMarker(COMP_STR); + comp.add(blue); + + multiComp = factory.getMarker(MULTI_COMP_STR); + multiComp.add(green); + multiComp.add(comp); + + } + public void testPrimitive() { + assertEquals(BLUE_STR, blue.getName()); + assertTrue(blue.contains(blue)); + + Marker blue2 = factory.getMarker(BLUE_STR); + assertEquals(BLUE_STR, blue2.getName()); + assertEquals(blue, blue2); + assertTrue(blue.contains(blue2)); + assertTrue(blue2.contains(blue)); + } + + public void testPrimitiveByName() { + assertTrue(blue.contains(BLUE_STR)); + } + + public void testComposite() { + assertTrue(comp.contains(comp)); + assertTrue(comp.contains(blue)); + } + + public void testCompositeByName() { + assertTrue(comp.contains(COMP_STR)); + assertTrue(comp.contains(BLUE_STR)); + } + + + public void testMultiComposite() { + assertTrue(multiComp.contains(comp)); + assertTrue(multiComp.contains(blue)); + assertTrue(multiComp.contains(green)); + assertFalse(multiComp.contains(red)); + } + + public void testMultiCompositeByName() { + assertTrue(multiComp.contains(COMP_STR)); + assertTrue(multiComp.contains(BLUE_STR)); + assertTrue(multiComp.contains(GREEN_STR)); + assertFalse(multiComp.contains(RED_STR)); + } + + + + +} diff --git a/slf4j-api/src/test/java/org/slf4j/impl/MessageFormatterTest.java b/slf4j-api/src/test/java/org/slf4j/impl/MessageFormatterTest.java new file mode 100644 index 00000000..a2402333 --- /dev/null +++ b/slf4j-api/src/test/java/org/slf4j/impl/MessageFormatterTest.java @@ -0,0 +1,177 @@ +/* + * 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.impl.MessageFormatter; + +import junit.framework.TestCase; + + +/** + * @author Ceki Gulcu + * + */ +public class MessageFormatterTest extends TestCase { + + Integer i1 = new Integer(1); + Integer i2 = new Integer(2); + Integer i3 = new Integer(3); + + public void testNull() { + String result; + result = MessageFormatter.format(null, i1); + assertEquals(null, result); + } + + public void testNullParam() { + String result; + + result = MessageFormatter.format("Value is {}.", null); + assertEquals("Value is null.", result); + + result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, null); + assertEquals("Val1 is null, val2 is null.", result); + + result = MessageFormatter.format("Val1 is {}, val2 is {}.", i1, null); + assertEquals("Val1 is 1, val2 is null.", result); + + result = MessageFormatter.format("Val1 is {}, val2 is {}.", null, i2); + assertEquals("Val1 is null, val2 is 2.", result); + + result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[]{null, null, null}); + assertEquals("Val1 is null, val2 is null, val3 is null", result); + + result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[]{null, i2, i3}); + assertEquals("Val1 is null, val2 is 2, val3 is 3", result); + + result = MessageFormatter.arrayFormat("Val1 is {}, val2 is {}, val3 is {}", new Integer[]{null, null, i3}); + assertEquals("Val1 is null, val2 is null, val3 is 3", result); + } + + + public void test1Param() { + String result; + + result = MessageFormatter.format("Value is {}.", i3); + assertEquals("Value is 3.", result); + + result = MessageFormatter.format("Value is {", i3); + assertEquals("Value is {", result); + + result = MessageFormatter.format("{} is larger than 2.", i3); + assertEquals("3 is larger than 2.", result); + + result = MessageFormatter.format("No subst", i3); + assertEquals("No subst", result); + + result = MessageFormatter.format("Incorrect {subst", i3); + assertEquals("Incorrect {subst", result); + + result = MessageFormatter.format("Escaped \\{} subst", i3); + assertEquals("Escaped {} subst", result); + + result = MessageFormatter.format("\\{Escaped", i3); + assertEquals("{Escaped", result); + + result = MessageFormatter.format("\\{}Escaped", i3); + assertEquals("{}Escaped", result); + + result = MessageFormatter.format("File name is \\{{}}.", "App folder.zip"); + assertEquals("File name is {App folder.zip}.", result); + } + + public void test2Param() { + String result; + + + result = MessageFormatter.format("Value {} is smaller than {}.", i1, i2); + assertEquals("Value 1 is smaller than 2.", result); + + result = MessageFormatter.format("Value {} is smaller than {}", i1, i2); + assertEquals("Value 1 is smaller than 2", result); + + result = MessageFormatter.format("{}{}", i1, i2); + assertEquals("12", result); + + result = MessageFormatter.format("Val1={}, Val2={", i1, i2); + assertEquals("Val1=1, Val2={", result); + + result = MessageFormatter.format("Value {} is smaller than \\{}", i1, i2); + assertEquals("Value 1 is smaller than {}", result); + + result = MessageFormatter.format("Value {} is smaller than \\{} tail", i1, i2); + assertEquals("Value 1 is smaller than {} tail", result); + + result = MessageFormatter.format("Value {} is smaller than \\{", i1, i2); + assertEquals("Value 1 is smaller than \\{", result); + + result = MessageFormatter.format("Value {} is smaller than \\{tail", i1, i2); + assertEquals("Value 1 is smaller than {tail", result); + + + result = MessageFormatter.format("Value \\{} is smaller than {}", i1, i2); + assertEquals("Value {} is smaller than 1", result); + } + + public void testArray() { + String result; + + Integer[] ia = new Integer[] {i1, i2, i3}; + + result = MessageFormatter.arrayFormat("Value {} is smaller than {} and {}.", ia); + assertEquals("Value 1 is smaller than 2 and 3.", result); + + result = MessageFormatter.arrayFormat("{}{}{}", ia); + assertEquals("123", result); + + result = MessageFormatter.arrayFormat("Value {} is smaller than {}.", ia); + assertEquals("Value 1 is smaller than 2.", result); + + result = MessageFormatter.arrayFormat("Value {} is smaller than {}", ia); + assertEquals("Value 1 is smaller than 2", result); + + result = MessageFormatter.arrayFormat("Val={}, {, Val={}", ia); + assertEquals("Val=1, {, Val={}", result); + + result = MessageFormatter.arrayFormat("Val={}, \\{, Val={}", ia); + assertEquals("Val=1, {, Val=2", result); + + + result = MessageFormatter.arrayFormat("Val1={}, Val2={", ia); + assertEquals("Val1=1, Val2={", result); + + + } + +}