Merge tag 'upstream/1.7.22'
Upstream version 1.7.22
Emmanuel Bourg
6 years ago
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>integration</artifactId> |
40 | 40 | * Runs a hosted version of Felix for testing purposes. Any bundle errors are |
41 | 41 | * reported via the FrameworkListener passed to the constructor. |
42 | 42 | * |
43 | * @author Ceki Gücü | |
43 | * @author Ceki Gülcü | |
44 | 44 | */ |
45 | 45 | public class FelixHost { |
46 | 46 |
4 | 4 | <parent> |
5 | 5 | <groupId>org.slf4j</groupId> |
6 | 6 | <artifactId>slf4j-parent</artifactId> |
7 | <version>1.7.21</version> | |
7 | <version>1.7.22</version> | |
8 | 8 | </parent> |
9 | 9 | |
10 | 10 | <modelVersion>4.0.0</modelVersion> |
320 | 320 | * Returns a string that uniquely identifies the specified object, including |
321 | 321 | * its class. |
322 | 322 | * <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 | |
324 | 324 | * 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. | |
326 | 326 | * |
327 | 327 | * @param o |
328 | 328 | * may be null. |
86 | 86 | /** Properties loaded from simplelog.properties */ |
87 | 87 | static protected final Properties simpleLogProps = new Properties(); |
88 | 88 | |
89 | /** The default format to use when formating dates */ | |
89 | /** The default format to use when formatting dates */ | |
90 | 90 | static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz"; |
91 | 91 | |
92 | 92 | /** Include the instance name in the log message? */ |
156 | 156 | if (null != in) { |
157 | 157 | try { |
158 | 158 | simpleLogProps.load(in); |
159 | in.close(); | |
160 | 159 | } catch (java.io.IOException e) { |
161 | 160 | // ignored |
162 | } | |
161 | } finally { | |
162 | try { | |
163 | in.close(); | |
164 | } catch (java.io.IOException e) { | |
165 | // ignored | |
166 | } | |
167 | } | |
163 | 168 | } |
164 | 169 | |
165 | 170 | showLogName = getBooleanProperty(systemPrefix + "showlogname", showLogName); |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>jul-to-slf4j</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 |
117 | 117 | * disposal. If this method returns <code>false</code>, meaning that |
118 | 118 | * a layout is not required, then layout configuration will be |
119 | 119 | * skipped even if there is available layout configuration |
120 | * information at the disposal of the configurator.. | |
120 | * information at the disposal of the configurator. | |
121 | 121 | * <p/> |
122 | 122 | * <p>In the rather exceptional case, where the appender |
123 | 123 | * implementation admits a layout but can also work without it, then |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | * Delegates tob {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J | |
147 | * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method in SLF4J | |
148 | 148 | */ |
149 | 149 | public boolean isWarnEnabled() { |
150 | 150 | return slf4jLogger.isWarnEnabled(); |
208 | 208 | |
209 | 209 | /** |
210 | 210 | * 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. | |
212 | 212 | * @return resolved object. |
213 | 213 | * @throws ObjectStreamException if exception during resolution. |
214 | 214 | */ |
215 | 215 | private Object readResolve() throws ObjectStreamException { |
216 | 216 | // |
217 | // if the deserizalized object is exactly an instance of Level | |
217 | // if the deserialized object is exactly an instance of Level | |
218 | 218 | // |
219 | 219 | if (getClass() == Level.class) { |
220 | 220 | return toLevel(level); |
18 | 18 | import org.apache.log4j.*; |
19 | 19 | |
20 | 20 | /** |
21 | Listen to events occuring within a {@link | |
21 | Listen to events occurring within a {@link | |
22 | 22 | org.apache.log4j.Hierarchy Hierarchy}. |
23 | 23 | |
24 | 24 | @author Ceki Gülcü |
30 | 30 | import org.junit.Test; |
31 | 31 | |
32 | 32 | /** |
33 | * @author Ceki Gücü | |
33 | * @author Ceki Gülcü | |
34 | 34 | */ |
35 | 35 | public class NDCTest { |
36 | 36 |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>osgi-over-slf4j</artifactId> |
5 | 5 | |
6 | 6 | <groupId>org.slf4j</groupId> |
7 | 7 | <artifactId>slf4j-parent</artifactId> |
8 | <version>1.7.21</version> | |
8 | <version>1.7.22</version> | |
9 | 9 | |
10 | 10 | <packaging>pom</packaging> |
11 | 11 | <name>SLF4J</name> |
407 | 407 | |
408 | 408 | <distributionManagement> |
409 | 409 | <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> | |
412 | 412 | </site> |
413 | 413 | |
414 | 414 | <repository> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-android</artifactId> |
25 | 25 | |
26 | 26 | import org.junit.Test; |
27 | 27 | |
28 | import static junit.framework.Assert.assertEquals; | |
28 | import static org.junit.Assert.assertEquals; | |
29 | 29 | |
30 | 30 | public class AndroidLoggerFactoryTest { |
31 | 31 | @Test |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-api</artifactId> |
41 | 41 | * i.e. this class, will delegate to the underlying system's MDC. Note that at |
42 | 42 | * this time, only two logging systems, namely log4j and logback, offer MDC |
43 | 43 | * 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 | |
45 | 45 | * and slf4j-nop, {@link NOPMDCAdapter} will be used. |
46 | 46 | * |
47 | 47 | * <p> |
41 | 41 | public static final NOPLogger NOP_LOGGER = new NOPLogger(); |
42 | 42 | |
43 | 43 | /** |
44 | * There is no point in creating multiple instances of NOPLOgger, | |
44 | * There is no point in creating multiple instances of NOPLogger, | |
45 | 45 | * except by derived classes, hence the protected access for the constructor. |
46 | 46 | */ |
47 | 47 | protected NOPLogger() { |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Serves as base class for named logger implementation. More significantly, this |
34 | * class establishes deserialization behavior. See @see #readResolve. | |
34 | * class establishes deserialization behavior. | |
35 | 35 | * |
36 | 36 | * @author Ceki Gulcu |
37 | * @see #readResolve | |
37 | 38 | * @since 1.5.3 |
38 | 39 | */ |
39 | 40 | abstract class NamedLoggerBase implements Logger, Serializable { |
46 | 46 | * The String form of the {@link ILoggerFactory} object that this |
47 | 47 | * <code>LoggerFactoryBinder</code> instance is <em>intended</em> to return. |
48 | 48 | * |
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 | |
50 | 50 | * 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. | |
52 | 52 | * |
53 | 53 | * @return the class name of the intended {@link ILoggerFactory} instance |
54 | 54 | */ |
37 | 37 | /** |
38 | 38 | * Put a context value (the <code>val</code> parameter) as identified with |
39 | 39 | * 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 | |
41 | 41 | * can be null only if the underlying implementation supports it. |
42 | 42 | * |
43 | 43 | * <p>If the current thread does not have a context map it is created as a side |
46 | 46 | * The String form of the {@link IMarkerFactory} object that this |
47 | 47 | * <code>MarkerFactoryBinder</code> instance is <em>intended</em> to return. |
48 | 48 | * |
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 | |
50 | 50 | * 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. | |
52 | 52 | * |
53 | 53 | * @return the class name of the intended {@link IMarkerFactory} instance |
54 | 54 | */ |
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 | } |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-ext</artifactId> |
40 | 40 | * instance does have any state beyond that of the {@link Logger} instance it |
41 | 41 | * wraps and its message conveyor. |
42 | 42 | * |
43 | * @author Ceki Gücü | |
43 | * @author Ceki Gülcü | |
44 | 44 | * |
45 | 45 | */ |
46 | 46 | public class LocLoggerFactory { |
87 | 87 | /** |
88 | 88 | * Serialize all the EventData items into an XML representation. |
89 | 89 | * |
90 | * @return an XML String containing all the EventDAta items. | |
90 | * @return an XML String containing all the EventData items. | |
91 | 91 | */ |
92 | 92 | public String toXML() { |
93 | 93 | return toXML(eventData); |
97 | 97 | * Serialize all the EventData items into an XML representation. |
98 | 98 | * |
99 | 99 | * @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. | |
101 | 101 | */ |
102 | 102 | public static String toXML(Map<String, Object> map) { |
103 | 103 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | * Returns an Iterator over all the entries in the EventDAta. | |
245 | * Returns an Iterator over all the entries in the EventData. | |
246 | 246 | * |
247 | 247 | * @return an Iterator that can be used to access all the event attributes. |
248 | 248 | */ |
57 | 57 | * Constructor that chains another Exception or Error and also allows a message |
58 | 58 | * to be specified. |
59 | 59 | * @param exceptionMessage The exception message. |
60 | * @param originalException The original excepton. | |
60 | * @param originalException The original exception. | |
61 | 61 | */ |
62 | 62 | public EventException(String exceptionMessage, Throwable originalException) { |
63 | 63 | super(exceptionMessage, originalException); |
39 | 39 | public class JavassistHelper { |
40 | 40 | |
41 | 41 | /** |
42 | * Create a javaassist source snippet which either is empty (for anything | |
42 | * Create a javassist source snippet which either is empty (for anything | |
43 | 43 | * which does not return a value) or a explanatory text around the $_ |
44 | * javaassist return value variable. | |
44 | * javassist return value variable. | |
45 | 45 | * |
46 | 46 | * @param method |
47 | 47 | * descriptor of method |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | * Return javaassist source snippet which lists all the parameters and their | |
84 | * Return javassist source snippet which lists all the parameters and their | |
85 | 85 | * values. If available the source names are extracted from the debug |
86 | 86 | * information and used, otherwise just a number is shown. |
87 | 87 | * |
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Should each method log entry (with parameters) and exit (with parameters |
82 | * and returnvalue)? | |
82 | * and return value)? | |
83 | 83 | * |
84 | 84 | * @param b |
85 | 85 | * value of flag |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | * Return a copy of the global stopwath of this Profiler instance. | |
216 | * Return a copy of the global stopwatch of this Profiler instance. | |
217 | 217 | * |
218 | 218 | * @return a copy of this instance's global stop watch |
219 | 219 | * @since 1.5.9 |
24 | 24 | package org.slf4j.profiler; |
25 | 25 | |
26 | 26 | /** |
27 | * A very basic @{link TimeInstrument} which can be started and stopped | |
27 | * A very basic {@link TimeInstrument} which can be started and stopped | |
28 | 28 | * once and only once. |
29 | 29 | * |
30 | 30 | * @author Ceki Gülcü |
42 | 42 | TimeInstrumentStatus getStatus(); |
43 | 43 | |
44 | 44 | /** |
45 | * Start tis time instrument. | |
45 | * Start this time instrument. | |
46 | 46 | * |
47 | 47 | * @param name |
48 | 48 | */ |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-jcl</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-jdk14</artifactId> |
34 | 34 | import java.util.logging.Level; |
35 | 35 | import java.util.logging.LogRecord; |
36 | 36 | |
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; | |
39 | 39 | import static org.junit.Assert.assertEquals; |
40 | 40 | import static org.junit.Assert.fail; |
41 | 41 |
46 | 46 | // when the code is guarded by a logger.isLoggable condition, |
47 | 47 | // duration is about 16 *micro*seconds for 1000 iterations |
48 | 48 | // 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 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | double debugLoop(int len) { |
31 | 31 | import java.io.ObjectOutputStream; |
32 | 32 | import java.io.Serializable; |
33 | 33 | |
34 | import junit.framework.Assert; | |
34 | import static org.junit.Assert.assertNotNull; | |
35 | 35 | |
36 | 36 | import org.junit.Test; |
37 | 37 | import org.slf4j.Logger; |
75 | 75 | ObjectInputStream in = new ObjectInputStream(is); |
76 | 76 | LoggerHolder lh2 = (LoggerHolder) in.readObject(); |
77 | 77 | |
78 | Assert.assertNotNull(lh2); | |
79 | Assert.assertNotNull(lh2.getLog()); | |
78 | assertNotNull(lh2); | |
79 | assertNotNull(lh2.getLog()); | |
80 | 80 | lh2.getLog().info("You must see this message as a log message"); |
81 | 81 | } |
82 | 82 |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-log4j12</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-migrator</artifactId> |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * 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 | |
58 | 58 | * replace all String containing "Log". |
59 | 59 | */ |
60 | 60 | public void test2() { |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
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 | |
85 | 85 | * without influence on Log declaration. |
86 | 86 | * |
87 | 87 | */ |
100 | 100 | |
101 | 101 | /** |
102 | 102 | * 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 | |
104 | 104 | */ |
105 | 105 | public void test4() { |
106 | 106 | Pattern pat = Pattern.compile("(\\sLog\\b)"); |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-nop</artifactId> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.21</version> | |
9 | <version>1.7.22</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-simple</artifactId> |
52 | 52 | * the special values "System.out" and "System.err". Default is "System.err". |
53 | 53 | * |
54 | 54 | * <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> | |
56 | 56 | * |
57 | 57 | * <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 | |
59 | 59 | * named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent |
60 | 60 | * logger will be used, and if none is set, then the value specified by |
61 | 61 | * <code>org.slf4j.simpleLogger.defaultLogLevel</code> will be used.</li> |
128 | 128 | private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT; |
129 | 129 | private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT; |
130 | 130 | 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; | |
131 | 134 | |
132 | 135 | private static boolean INITIALIZED = false; |
133 | 136 | |
178 | 181 | return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop); |
179 | 182 | } |
180 | 183 | |
181 | // Initialize class attributes. | |
182 | // Load properties file, if found. | |
183 | // Override with system properties. | |
184 | static void init() { | |
184 | static void lazyInit() { | |
185 | 185 | if (INITIALIZED) { |
186 | 186 | return; |
187 | 187 | } |
188 | 188 | INITIALIZED = true; |
189 | init(); | |
190 | } | |
191 | ||
192 | static void init() { | |
189 | 193 | loadProperties(); |
190 | 194 | |
191 | 195 | String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null); |
244 | 248 | if (null != in) { |
245 | 249 | try { |
246 | 250 | SIMPLE_LOGGER_PROPS.load(in); |
247 | in.close(); | |
248 | 251 | } catch (java.io.IOException e) { |
249 | 252 | // ignored |
253 | } finally { | |
254 | try { | |
255 | in.close(); | |
256 | } catch (java.io.IOException e) { | |
257 | // ignored | |
258 | } | |
250 | 259 | } |
251 | 260 | } |
252 | 261 | } |
294 | 303 | return LOG_LEVEL_WARN; |
295 | 304 | } else if ("error".equalsIgnoreCase(levelStr)) { |
296 | 305 | return LOG_LEVEL_ERROR; |
306 | } else if ("off".equalsIgnoreCase(levelStr)) { | |
307 | return LOG_LEVEL_OFF; | |
297 | 308 | } |
298 | 309 | // assume INFO by default |
299 | 310 | return LOG_LEVEL_INFO; |
41 | 41 | |
42 | 42 | public SimpleLoggerFactory() { |
43 | 43 | loggerMap = new ConcurrentHashMap<String, Logger>(); |
44 | SimpleLogger.init(); | |
44 | SimpleLogger.lazyInit(); | |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
27 | 27 | import org.junit.Before; |
28 | 28 | import org.junit.Test; |
29 | 29 | |
30 | import static junit.framework.Assert.assertEquals; | |
31 | import static junit.framework.Assert.assertNull; | |
30 | import static org.junit.Assert.*; | |
32 | 31 | |
33 | 32 | public class SimpleLoggerTest { |
34 | 33 | |
50 | 49 | assertEquals("info", simpleLogger.recursivelyComputeLevelString()); |
51 | 50 | } |
52 | 51 | |
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 | ||
53 | 60 | @Test |
54 | 61 | public void loggerNameWithNoDots_WithLevel() { |
55 | 62 | SimpleLogger simpleLogger = new SimpleLogger("a"); |