Codebase list libslf4j-java / 8a713f5
New upstream version 1.7.22 Emmanuel Bourg 7 years ago
47 changed file(s) with 149 addition(s) and 70 deletion(s). Raw diff Collapse all Expand all
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>integration</artifactId>
4040 * Runs a hosted version of Felix for testing purposes. Any bundle errors are
4141 * reported via the FrameworkListener passed to the constructor.
4242 *
43 * @author Ceki G&uuml;c&uuml;
43 * @author Ceki G&uuml;lc&uuml;
4444 */
4545 public class FelixHost {
4646
44 <parent>
55 <groupId>org.slf4j</groupId>
66 <artifactId>slf4j-parent</artifactId>
7 <version>1.7.21</version>
7 <version>1.7.22</version>
88 </parent>
99
1010 <modelVersion>4.0.0</modelVersion>
320320 * Returns a string that uniquely identifies the specified object, including
321321 * its class.
322322 * <p>
323 * The returned string is of form "classname@hashcode", ie is the same as the
323 * The returned string is of form "classname@hashcode", i.e. is the same as the
324324 * return value of the Object.toString() method, but works even when the
325 * specified object's class has overidden the toString method.
325 * specified object's class has overridden the toString method.
326326 *
327327 * @param o
328328 * may be null.
8686 /** Properties loaded from simplelog.properties */
8787 static protected final Properties simpleLogProps = new Properties();
8888
89 /** The default format to use when formating dates */
89 /** The default format to use when formatting dates */
9090 static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz";
9191
9292 /** Include the instance name in the log message? */
156156 if (null != in) {
157157 try {
158158 simpleLogProps.load(in);
159 in.close();
160159 } catch (java.io.IOException e) {
161160 // ignored
162 }
161 } finally {
162 try {
163 in.close();
164 } catch (java.io.IOException e) {
165 // ignored
166 }
167 }
163168 }
164169
165170 showLogName = getBooleanProperty(systemPrefix + "showlogname", showLogName);
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>jul-to-slf4j</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212
117117 * disposal. If this method returns <code>false</code>, meaning that
118118 * a layout is not required, then layout configuration will be
119119 * skipped even if there is available layout configuration
120 * information at the disposal of the configurator..
120 * information at the disposal of the configurator.
121121 * <p/>
122122 * <p>In the rather exceptional case, where the appender
123123 * implementation admits a layout but can also work without it, then
144144 }
145145
146146 /**
147 * Delegates tob {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J
147 * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J
148148 */
149149 public boolean isWarnEnabled() {
150150 return slf4jLogger.isWarnEnabled();
208208
209209 /**
210210 * Resolved deserialized level to one of the stock instances.
211 * May be overriden in classes derived from Level.
211 * May be overridden in classes derived from Level.
212212 * @return resolved object.
213213 * @throws ObjectStreamException if exception during resolution.
214214 */
215215 private Object readResolve() throws ObjectStreamException {
216216 //
217 // if the deserizalized object is exactly an instance of Level
217 // if the deserialized object is exactly an instance of Level
218218 //
219219 if (getClass() == Level.class) {
220220 return toLevel(level);
1818 import org.apache.log4j.*;
1919
2020 /**
21 Listen to events occuring within a {@link
21 Listen to events occurring within a {@link
2222 org.apache.log4j.Hierarchy Hierarchy}.
2323
2424 @author Ceki G&uuml;lc&uuml;
3030 import org.junit.Test;
3131
3232 /**
33 * @author Ceki G&uuml;c&uuml;
33 * @author Ceki G&uuml;lc&uuml;
3434 */
3535 public class NDCTest {
3636
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>osgi-over-slf4j</artifactId>
55
66 <groupId>org.slf4j</groupId>
77 <artifactId>slf4j-parent</artifactId>
8 <version>1.7.21</version>
8 <version>1.7.22</version>
99
1010 <packaging>pom</packaging>
1111 <name>SLF4J</name>
407407
408408 <distributionManagement>
409409 <site>
410 <id>tao</id>
411 <url>scp://tao.qos.ch/var/www/www.slf4j.org/htdocs/</url>
410 <id>qos_ch</id>
411 <url>scp://te.qos.ch/var/www/www.slf4j.org/htdocs/</url>
412412 </site>
413413
414414 <repository>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-android</artifactId>
2525
2626 import org.junit.Test;
2727
28 import static junit.framework.Assert.assertEquals;
28 import static org.junit.Assert.assertEquals;
2929
3030 public class AndroidLoggerFactoryTest {
3131 @Test
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-api</artifactId>
4141 * i.e. this class, will delegate to the underlying system's MDC. Note that at
4242 * this time, only two logging systems, namely log4j and logback, offer MDC
4343 * functionality. For java.util.logging which does not support MDC,
44 * {@link BasicMDCAdapter} will be used. For other systems, i.e slf4j-simple
44 * {@link BasicMDCAdapter} will be used. For other systems, i.e. slf4j-simple
4545 * and slf4j-nop, {@link NOPMDCAdapter} will be used.
4646 *
4747 * <p>
4141 public static final NOPLogger NOP_LOGGER = new NOPLogger();
4242
4343 /**
44 * There is no point in creating multiple instances of NOPLOgger,
44 * There is no point in creating multiple instances of NOPLogger,
4545 * except by derived classes, hence the protected access for the constructor.
4646 */
4747 protected NOPLogger() {
3131
3232 /**
3333 * Serves as base class for named logger implementation. More significantly, this
34 * class establishes deserialization behavior. See @see #readResolve.
34 * class establishes deserialization behavior.
3535 *
3636 * @author Ceki Gulcu
37 * @see #readResolve
3738 * @since 1.5.3
3839 */
3940 abstract class NamedLoggerBase implements Logger, Serializable {
4646 * The String form of the {@link ILoggerFactory} object that this
4747 * <code>LoggerFactoryBinder</code> instance is <em>intended</em> to return.
4848 *
49 * <p>This method allows the developer to intterogate this binder's intention
49 * <p>This method allows the developer to interrogate this binder's intention
5050 * which may be different from the {@link ILoggerFactory} instance it is able to
51 * yield in practice. The discrepency should only occur in case of errors.
51 * yield in practice. The discrepancy should only occur in case of errors.
5252 *
5353 * @return the class name of the intended {@link ILoggerFactory} instance
5454 */
3737 /**
3838 * Put a context value (the <code>val</code> parameter) as identified with
3939 * the <code>key</code> parameter into the current thread's context map.
40 * The <code>key</code> parameter cannot be null. The code>val</code> parameter
40 * The <code>key</code> parameter cannot be null. The <code>val</code> parameter
4141 * can be null only if the underlying implementation supports it.
4242 *
4343 * <p>If the current thread does not have a context map it is created as a side
4646 * The String form of the {@link IMarkerFactory} object that this
4747 * <code>MarkerFactoryBinder</code> instance is <em>intended</em> to return.
4848 *
49 * <p>This method allows the developer to intterogate this binder's intention
49 * <p>This method allows the developer to interrogate this binder's intention
5050 * which may be different from the {@link IMarkerFactory} instance it is able to
51 * return. Such a discrepency should only occur in case of errors.
51 * return. Such a discrepancy should only occur in case of errors.
5252 *
5353 * @return the class name of the intended {@link IMarkerFactory} instance
5454 */
0 package org.slf4j;
1
2 import org.junit.Ignore;
3 import org.junit.Test;
4
5 public class FindStaticLoggerBinderPathsPerfTest {
6
7 @Test
8 @Ignore
9 public void test() {
10 long duration = timeFindBindingSetCall();
11 System.out.println(duration / (1000) + " microseconds");
12
13 int count = 10;
14 long sum = 0;
15 for (int i = 0; i < count; i++) {
16 sum += timeFindBindingSetCall();
17 }
18 System.out.println(sum / (count * 1000) + " microseconds in average");
19 }
20
21 @Test
22 public void testAsync() throws InterruptedException {
23 long start = System.nanoTime();
24 FindPathSetThread thread = new FindPathSetThread();
25 thread.start();
26 long end = System.nanoTime();
27
28 long duration = end - start;
29 System.out.println(duration / (1000) + " microseconds");
30
31 thread.join();
32 }
33
34 long timeFindBindingSetCall() {
35 long start = System.nanoTime();
36
37 LoggerFactory.findPossibleStaticLoggerBinderPathSet();
38 long end = System.nanoTime();
39 return end - start;
40
41 }
42
43 static class FindPathSetThread extends Thread {
44
45 public void run() {
46 long start = System.nanoTime();
47 LoggerFactory.findPossibleStaticLoggerBinderPathSet();
48 long end = System.nanoTime();
49
50 System.out.println("Found set in " + (end - start)/1000 + " microseconds");
51
52 }
53 }
54 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-ext</artifactId>
4040 * instance does have any state beyond that of the {@link Logger} instance it
4141 * wraps and its message conveyor.
4242 *
43 * @author Ceki G&uuml;c&uuml;
43 * @author Ceki G&uuml;lc&uuml;
4444 *
4545 */
4646 public class LocLoggerFactory {
8787 /**
8888 * Serialize all the EventData items into an XML representation.
8989 *
90 * @return an XML String containing all the EventDAta items.
90 * @return an XML String containing all the EventData items.
9191 */
9292 public String toXML() {
9393 return toXML(eventData);
9797 * Serialize all the EventData items into an XML representation.
9898 *
9999 * @param map the Map to transform
100 * @return an XML String containing all the EventDAta items.
100 * @return an XML String containing all the EventData items.
101101 */
102102 public static String toXML(Map<String, Object> map) {
103103 ByteArrayOutputStream baos = new ByteArrayOutputStream();
242242 }
243243
244244 /**
245 * Returns an Iterator over all the entries in the EventDAta.
245 * Returns an Iterator over all the entries in the EventData.
246246 *
247247 * @return an Iterator that can be used to access all the event attributes.
248248 */
5757 * Constructor that chains another Exception or Error and also allows a message
5858 * to be specified.
5959 * @param exceptionMessage The exception message.
60 * @param originalException The original excepton.
60 * @param originalException The original exception.
6161 */
6262 public EventException(String exceptionMessage, Throwable originalException) {
6363 super(exceptionMessage, originalException);
3939 public class JavassistHelper {
4040
4141 /**
42 * Create a javaassist source snippet which either is empty (for anything
42 * Create a javassist source snippet which either is empty (for anything
4343 * which does not return a value) or a explanatory text around the $_
44 * javaassist return value variable.
44 * javassist return value variable.
4545 *
4646 * @param method
4747 * descriptor of method
8181 }
8282
8383 /**
84 * Return javaassist source snippet which lists all the parameters and their
84 * Return javassist source snippet which lists all the parameters and their
8585 * values. If available the source names are extracted from the debug
8686 * information and used, otherwise just a number is shown.
8787 *
7979
8080 /**
8181 * Should each method log entry (with parameters) and exit (with parameters
82 * and returnvalue)?
82 * and return value)?
8383 *
8484 * @param b
8585 * value of flag
213213 }
214214
215215 /**
216 * Return a copy of the global stopwath of this Profiler instance.
216 * Return a copy of the global stopwatch of this Profiler instance.
217217 *
218218 * @return a copy of this instance's global stop watch
219219 * @since 1.5.9
2424 package org.slf4j.profiler;
2525
2626 /**
27 * A very basic @{link TimeInstrument} which can be started and stopped
27 * A very basic {@link TimeInstrument} which can be started and stopped
2828 * once and only once.
2929 *
3030 * @author Ceki G&uuml;lc&uuml;
4242 TimeInstrumentStatus getStatus();
4343
4444 /**
45 * Start tis time instrument.
45 * Start this time instrument.
4646 *
4747 * @param name
4848 */
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jcl</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jdk14</artifactId>
3434 import java.util.logging.Level;
3535 import java.util.logging.LogRecord;
3636
37 import static junit.framework.Assert.assertNotNull;
38 import static junit.framework.Assert.assertNull;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertNull;
3939 import static org.junit.Assert.assertEquals;
4040 import static org.junit.Assert.fail;
4141
4646 // when the code is guarded by a logger.isLoggable condition,
4747 // duration is about 16 *micro*seconds for 1000 iterations
4848 // when it is not guarded the figure is 90 milliseconds,
49 // i.e a ration of 1 to 5000
49 // i.e. a ration of 1 to 5000
5050 }
5151
5252 double debugLoop(int len) {
3131 import java.io.ObjectOutputStream;
3232 import java.io.Serializable;
3333
34 import junit.framework.Assert;
34 import static org.junit.Assert.assertNotNull;
3535
3636 import org.junit.Test;
3737 import org.slf4j.Logger;
7575 ObjectInputStream in = new ObjectInputStream(is);
7676 LoggerHolder lh2 = (LoggerHolder) in.readObject();
7777
78 Assert.assertNotNull(lh2);
79 Assert.assertNotNull(lh2.getLog());
78 assertNotNull(lh2);
79 assertNotNull(lh2.getLog());
8080 lh2.getLog().info("You must see this message as a log message");
8181 }
8282
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-log4j12</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-migrator</artifactId>
5454
5555 /**
5656 * In this test we replace, using the simple Pattern (Log), the full Log
57 * declaration and instanciation. This is not convenient because we will also
57 * declaration and instantiation. This is not convenient because we will also
5858 * replace all String containing "Log".
5959 */
6060 public void test2() {
8181 }
8282
8383 /**
84 * In this test we use a simple Pattern to replace the log instanciation
84 * In this test we use a simple Pattern to replace the log instantiation
8585 * without influence on Log declaration.
8686 *
8787 */
100100
101101 /**
102102 * In this test we try to replace keyword Log without influence on String
103 * containg Log We see that we have to use two differents Patterns
103 * containing Log We see that we have to use two different Patterns
104104 */
105105 public void test4() {
106106 Pattern pat = Pattern.compile("(\\sLog\\b)");
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-nop</artifactId>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-simple</artifactId>
5252 * the special values "System.out" and "System.err". Default is "System.err".
5353 *
5454 * <li><code>org.slf4j.simpleLogger.defaultLogLevel</code> - Default log level for all instances of SimpleLogger.
55 * Must be one of ("trace", "debug", "info", "warn", or "error"). If not specified, defaults to "info". </li>
55 * Must be one of ("trace", "debug", "info", "warn", "error" or "off"). If not specified, defaults to "info". </li>
5656 *
5757 * <li><code>org.slf4j.simpleLogger.log.<em>a.b.c</em></code> - Logging detail level for a SimpleLogger instance
58 * named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", or "error". When a SimpleLogger
58 * named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger
5959 * named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent
6060 * logger will be used, and if none is set, then the value specified by
6161 * <code>org.slf4j.simpleLogger.defaultLogLevel</code> will be used.</li>
128128 private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
129129 private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
130130 private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
131 // The OFF level can only be used in configuration files to disable logging. It has
132 // no printing method associated with it in o.s.Logger interface.
133 private static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10;
131134
132135 private static boolean INITIALIZED = false;
133136
178181 return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop);
179182 }
180183
181 // Initialize class attributes.
182 // Load properties file, if found.
183 // Override with system properties.
184 static void init() {
184 static void lazyInit() {
185185 if (INITIALIZED) {
186186 return;
187187 }
188188 INITIALIZED = true;
189 init();
190 }
191
192 static void init() {
189193 loadProperties();
190194
191195 String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
244248 if (null != in) {
245249 try {
246250 SIMPLE_LOGGER_PROPS.load(in);
247 in.close();
248251 } catch (java.io.IOException e) {
249252 // ignored
253 } finally {
254 try {
255 in.close();
256 } catch (java.io.IOException e) {
257 // ignored
258 }
250259 }
251260 }
252261 }
294303 return LOG_LEVEL_WARN;
295304 } else if ("error".equalsIgnoreCase(levelStr)) {
296305 return LOG_LEVEL_ERROR;
306 } else if ("off".equalsIgnoreCase(levelStr)) {
307 return LOG_LEVEL_OFF;
297308 }
298309 // assume INFO by default
299310 return LOG_LEVEL_INFO;
4141
4242 public SimpleLoggerFactory() {
4343 loggerMap = new ConcurrentHashMap<String, Logger>();
44 SimpleLogger.init();
44 SimpleLogger.lazyInit();
4545 }
4646
4747 /**
2727 import org.junit.Before;
2828 import org.junit.Test;
2929
30 import static junit.framework.Assert.assertEquals;
31 import static junit.framework.Assert.assertNull;
30 import static org.junit.Assert.*;
3231
3332 public class SimpleLoggerTest {
3433
5049 assertEquals("info", simpleLogger.recursivelyComputeLevelString());
5150 }
5251
52 @Test
53 public void offLevel() {
54 System.setProperty(A_KEY, "off");
55 SimpleLogger simpleLogger = new SimpleLogger("a");
56 assertEquals("off", simpleLogger.recursivelyComputeLevelString());
57 assertFalse(simpleLogger.isErrorEnabled());
58 }
59
5360 @Test
5461 public void loggerNameWithNoDots_WithLevel() {
5562 SimpleLogger simpleLogger = new SimpleLogger("a");
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.21</version>
9 <version>1.7.22</version>
1010 </parent>
1111
1212 <artifactId>slf4j-site</artifactId>