Package list libslf4j-java / upstream/1.7.19
Imported Upstream version 1.7.19 Emmanuel Bourg 5 years ago
108 changed file(s) with 1778 addition(s) and 423 deletion(s). Raw diff Collapse all Expand all
5555 <pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" />
5656 </path >
5757
58
58
5959 <path id="incompatibleMultiBinding">
6060 <pathelement location="target/test-classes/" />
6161 <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" />
102102
103103 <target name="testAll" depends="init,
104104 testMissingSingletonMethod,
105 testMismatch,
105 testMismatch,
106106 testMatch,
107107 testMultiBinding,
108108 testIncompatibleMultiBinding,
130130 </junit>
131131
132132 </target>
133
134
135 <target name="testMixed17">
136
137 <junit printsummary="yes" fork="no" haltonfailure="yes">
138 <classpath refid="pathMixed17" />
139 <formatter type="plain" />
140 <test fork="yes" todir="target/unit-reports"
141 outfile="TEST-MIXED-17"
142 name="org.slf4j.VersionMismatchAssertionTest" />
143 </junit>
144 </target>
145
133146
134147 <target name="testMismatch">
135148
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>integration</artifactId>
00 /**
1 * Copyright (c) 2004-2011 QOS.ch
1 * Copyright (c) 2004-2016 QOS.ch
22 * All rights reserved.
33 *
44 * Permission is hereby granted, free of charge, to any person obtaining
66
77 public class Issue324Test extends TestCase {
88
9
109 public void testLoggerCreationInPresenseOfSecurityManager() {
1110 String currentDir = System.getProperty("user.dir");
12 System.out.println("currentDir:"+currentDir);
11 System.out.println("currentDir:" + currentDir);
1312 Logger logger = LoggerFactory.getLogger(Issue324Test.class);
1413 logger.debug("hello");
1514 }
44 <parent>
55 <groupId>org.slf4j</groupId>
66 <artifactId>slf4j-parent</artifactId>
7 <version>1.7.14</version>
7 <version>1.7.19</version>
88 </parent>
99
1010 <modelVersion>4.0.0</modelVersion>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>jul-to-slf4j</artifactId>
3232 import org.junit.Before;
3333 import org.junit.Test;
3434 import org.slf4j.LoggerFactory;
35
3536 public class SLF4JBridgeHandlerPerfTest {
3637
3738 static String LOGGER_NAME = "yay";
4849 org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger(LOGGER_NAME);
4950
5051 Handler[] existingHandlers;
51
5252
5353 @Before
5454 public void setUp() throws Exception {
3434 import org.junit.After;
3535 import org.junit.Before;
3636 import org.junit.Test;
37 public class SLF4JBridgeHandlerTest {
37
38 public class SLF4JBridgeHandlerTest {
3839
3940 static String LOGGER_NAME = "yay";
4041
4142 ListAppender listAppender = new ListAppender();
4243 org.apache.log4j.Logger log4jRoot;
4344 java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay");
44
4545
4646 @Before
4747 public void setUp() throws Exception {
178178 }
179179
180180 // See http://jira.qos.ch/browse/SLF4J-337
181
181
182182 @Test
183183 public void illFormattedInputShouldBeReturnedAsIs() {
184184 SLF4JBridgeHandler.install();
185185 String msg = "foo {18=bad} {0}";
186
186
187187 julLogger.log(Level.INFO, msg, "ignored parameter due to IllegalArgumentException");
188188 assertEquals(1, listAppender.list.size());
189189 LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
190190 assertEquals(msg, le.getMessage());
191191 }
192
192
193193 void assertLevel(int index, org.apache.log4j.Level expectedLevel) {
194194 LoggingEvent le = (LoggingEvent) listAppender.list.get(index);
195195 assertEquals(expectedLevel, le.getLevel());
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212
345345 public void setLevel(Level level) {
346346 // nothing to do
347347 }
348
348
349349 public boolean getAdditivity() {
350350 return false;
351351 }
352
352
353353 public void assertLog(boolean assertion, String msg) {
354 if(!assertion)
354 if (!assertion)
355355 error(msg);
356356 }
357357
33 Bundle-Name: log4j-over-slf4j
44 Bundle-Vendor: SLF4J.ORG
55 Bundle-RequiredExecutionEnvironment: J2SE-1.5
6 Export-Package: org.apache.log4j;version=${log4j.version},org.apache.log4j.helpers;version=${log4j.version},org.apache.log4j.spi;version=${log4j.version},org.apache.log4j.xml;version=${log4j.version}
7 Import-Package: org.slf4j;version=${slf4j.api.minimum.compatible.version}, org.slf4j.helpers;version=${slf4j.api.minimum.compatible.version}, org.slf4j.spi;version=${slf4j.api.minimum.compatible.version}
6 Export-Package: org.apache.log4j;version=${log4j.version},
7 org.apache.log4j.helpers;version=${log4j.version},
8 org.apache.log4j.spi;version=${log4j.version},
9 org.apache.log4j.xml;version=${log4j.version}
10 Import-Package: org.slf4j;version=${slf4j.api.minimum.compatible.version},
11 org.slf4j.helpers;version=${slf4j.api.minimum.compatible.version},
12 org.slf4j.spi;version=${slf4j.api.minimum.compatible.version}
3131 import org.apache.log4j.Category;
3232 import org.apache.log4j.Logger;
3333 import org.junit.Test;
34 public class Bug131 {
34
35 public class Bug131 {
3536
3637 @Test
3738 public void testBug131() {
3232 import org.apache.log4j.Logger;
3333 import org.junit.Test;
3434
35 public class Bug139 {
35 public class Bug139 {
3636
3737 @Test
3838 public void test() {
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</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.14</version>
8 <version>1.7.19</version>
99
1010 <packaging>pom</packaging>
1111 <name>SLF4J</name>
2727 </licenses>
2828
2929 <scm>
30 <url>https://github.com/ceki/slf4j</url>
30 <url>https://github.com/qos-ch/slf4j</url>
3131 <connection>git@github.com:qos-ch/slf4j.git</connection>
3232 </scm>
3333
4343 <cal10n.version>0.8.1</cal10n.version>
4444 <log4j.version>1.2.17</log4j.version>
4545 <logback.version>1.0.13</logback.version>
46 <junit.version>4.10</junit.version>
46 <junit.version>4.12</junit.version>
4747 <maven-site-plugin.version>3.3</maven-site-plugin.version>
4848 <javadoc.plugin.version>2.10.2</javadoc.plugin.version>
4949 </properties>
181181 <plugin>
182182 <groupId>org.apache.maven.plugins</groupId>
183183 <artifactId>maven-surefire-plugin</artifactId>
184 <version>2.10</version>
184 <version>2.19.1</version>
185185 <configuration>
186 <forkMode>once</forkMode>
186 <forkCount>2C</forkCount>
187 <reuseForks>true</reuseForks>
187188 <reportFormat>plain</reportFormat>
188189 <trimStackTrace>false</trimStackTrace>
189190 <excludes>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-android</artifactId>
8080 class AndroidLoggerAdapter extends MarkerIgnoringBase {
8181 private static final long serialVersionUID = -1227274521521287937L;
8282
83
8483 /**
8584 * Package access allows only {@link AndroidLoggerFactory} to instantiate
8685 * SimpleLogger instances.
116116 // Take leading part and append '*' to indicate that it was truncated
117117 int length = loggerName.length();
118118 int lastPeriodIndex = loggerName.lastIndexOf('.');
119 return lastPeriodIndex != -1 && length - (lastPeriodIndex + 1) <= TAG_MAX_LENGTH
120 ? loggerName.substring(lastPeriodIndex + 1)
121 : '*' + loggerName.substring(length - TAG_MAX_LENGTH + 1);
119 return lastPeriodIndex != -1 && length - (lastPeriodIndex + 1) <= TAG_MAX_LENGTH ? loggerName.substring(lastPeriodIndex + 1) : '*' + loggerName
120 .substring(length - TAG_MAX_LENGTH + 1);
122121 }
123122 }
5757 // to avoid constant folding by the compiler, this field must *not* be final
5858 public static String REQUESTED_API_VERSION = "1.6.99"; // !final
5959
60
61
6260 private static final String loggerFactoryClassStr = AndroidLoggerFactory.class.getName();
6361
6462 /**
2626 import org.slf4j.helpers.NOPMDCAdapter;
2727 import org.slf4j.spi.MDCAdapter;
2828
29
3029 /**
3130 * This implementation is bound to {@link NOPMDCAdapter}.
3231 *
3534 */
3635 public class StaticMDCBinder {
3736
38 /**
39 * The unique instance of this class.
40 */
41 public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
37 /**
38 * The unique instance of this class.
39 */
40 public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
4241
43 private StaticMDCBinder() {
44 }
45
46 /**
47 * Return the singleton of this class.
48 *
49 * @return the StaticMDCBinder singleton
50 * @since 1.7.14
51 */
52 public static final StaticMDCBinder getSingleton() {
53 return SINGLETON;
54 }
55 /**
56 * Currently this method always returns an instance of
57 * {@link NOPMDCAdapter}.
58 */
59 public MDCAdapter getMDCA() {
60 return new NOPMDCAdapter();
61 }
62
63 public String getMDCAdapterClassStr() {
64 return NOPMDCAdapter.class.getName();
65 }
42 private StaticMDCBinder() {
43 }
44
45 /**
46 * Return the singleton of this class.
47 *
48 * @return the StaticMDCBinder singleton
49 * @since 1.7.14
50 */
51 public static final StaticMDCBinder getSingleton() {
52 return SINGLETON;
53 }
54
55 /**
56 * Currently this method always returns an instance of
57 * {@link NOPMDCAdapter}.
58 */
59 public MDCAdapter getMDCA() {
60 return new NOPMDCAdapter();
61 }
62
63 public String getMDCAdapterClassStr() {
64 return NOPMDCAdapter.class.getName();
65 }
6666 }
3838 */
3939 public class StaticMarkerBinder implements MarkerFactoryBinder {
4040
41 /**
42 * The unique instance of this class.
43 */
44 public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
45
46 final IMarkerFactory markerFactory = new BasicMarkerFactory();
47
48 private StaticMarkerBinder() {
49 }
50
51 /**
52 * Return the singleton of this class.
53 *
54 * @return the StaticMarkerBinder singleton
55 * @since 1.7.14
56 */
57 public static StaticMarkerBinder getSingleton() {
58 return SINGLETON;
59 }
60
61 /**
62 * Currently this method always returns an instance of
63 * {@link BasicMarkerFactory}.
64 */
65 public IMarkerFactory getMarkerFactory() {
66 return markerFactory;
67 }
68
69 /**
70 * Currently, this method returns the class name of
71 * {@link BasicMarkerFactory}.
72 */
73 public String getMarkerFactoryClassStr() {
74 return BasicMarkerFactory.class.getName();
75 }
41 /**
42 * The unique instance of this class.
43 */
44 public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
45
46 final IMarkerFactory markerFactory = new BasicMarkerFactory();
47
48 private StaticMarkerBinder() {
49 }
50
51 /**
52 * Return the singleton of this class.
53 *
54 * @return the StaticMarkerBinder singleton
55 * @since 1.7.14
56 */
57 public static StaticMarkerBinder getSingleton() {
58 return SINGLETON;
59 }
60
61 /**
62 * Currently this method always returns an instance of
63 * {@link BasicMarkerFactory}.
64 */
65 public IMarkerFactory getMarkerFactory() {
66 return markerFactory;
67 }
68
69 /**
70 * Currently, this method returns the class name of
71 * {@link BasicMarkerFactory}.
72 */
73 public String getMarkerFactoryClassStr() {
74 return BasicMarkerFactory.class.getName();
75 }
7676 }
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-api</artifactId>
2525
2626 import java.io.IOException;
2727 import java.net.URL;
28 import java.util.ArrayList;
2829 import java.util.Arrays;
2930 import java.util.Enumeration;
3031 import java.util.LinkedHashSet;
3132 import java.util.List;
3233 import java.util.Set;
33
34 import java.util.concurrent.LinkedBlockingQueue;
35
36 import org.slf4j.event.SubstituteLoggingEvent;
3437 import org.slf4j.helpers.NOPLoggerFactory;
3538 import org.slf4j.helpers.SubstituteLogger;
3639 import org.slf4j.helpers.SubstituteLoggerFactory;
6770 static final String VERSION_MISMATCH = CODES_PREFIX + "#version_mismatch";
6871 static final String SUBSTITUTE_LOGGER_URL = CODES_PREFIX + "#substituteLogger";
6972 static final String LOGGER_NAME_MISMATCH_URL = CODES_PREFIX + "#loggerNameMismatch";
73 static final String REPLAY_URL = CODES_PREFIX + "#replay";
7074
7175 static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
7276 static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory could not be successfully initialized. See also " + UNSUCCESSFUL_INIT_URL;
7781 static final int SUCCESSFUL_INITIALIZATION = 3;
7882 static final int NOP_FALLBACK_INITIALIZATION = 4;
7983
80 static int INITIALIZATION_STATE = UNINITIALIZED;
81 static SubstituteLoggerFactory TEMP_FACTORY = new SubstituteLoggerFactory();
84 static volatile int INITIALIZATION_STATE = UNINITIALIZED;
85 static SubstituteLoggerFactory SUBST_FACTORY = new SubstituteLoggerFactory();
8286 static NOPLoggerFactory NOP_FALLBACK_FACTORY = new NOPLoggerFactory();
8387
8488 // Support for detecting mismatched logger names.
8589 static final String DETECT_LOGGER_NAME_MISMATCH_PROPERTY = "slf4j.detectLoggerNameMismatch";
8690 static final String JAVA_VENDOR_PROPERTY = "java.vendor.url";
87
91
8892 static boolean DETECT_LOGGER_NAME_MISMATCH = Util.safeGetBooleanSystemProperty(DETECT_LOGGER_NAME_MISMATCH_PROPERTY);
8993
9094 /**
113117 */
114118 static void reset() {
115119 INITIALIZATION_STATE = UNINITIALIZED;
116 TEMP_FACTORY = new SubstituteLoggerFactory();
117120 }
118121
119122 private final static void performInitialization() {
135138
136139 private final static void bind() {
137140 try {
138 Set<URL> staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
139 reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
141 Set<URL> staticLoggerBinderPathSet = null;
142 // skip check under android, see also http://jira.qos.ch/browse/SLF4J-328
143 if (!isAndroid()) {
144 staticLoggerBinderPathSet = findPossibleStaticLoggerBinderPathSet();
145 reportMultipleBindingAmbiguity(staticLoggerBinderPathSet);
146 }
140147 // the next line does the binding
141148 StaticLoggerBinder.getSingleton();
142149 INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
143150 reportActualBinding(staticLoggerBinderPathSet);
144 fixSubstitutedLoggers();
151 replayEvents();
145152 } catch (NoClassDefFoundError ncde) {
146153 String msg = ncde.getMessage();
147154 if (messageContainsOrgSlf4jImplStaticLoggerBinder(msg)) {
173180 Util.report("Failed to instantiate SLF4J LoggerFactory", t);
174181 }
175182
176 private final static void fixSubstitutedLoggers() {
177 List<SubstituteLogger> loggers = TEMP_FACTORY.getLoggers();
178
179 if (loggers.isEmpty()) {
183 private static void replayEvents() {
184 final LinkedBlockingQueue<SubstituteLoggingEvent> queue = SUBST_FACTORY.getEventQueue();
185 final int queueSize = queue.size();
186 int count = 0;
187 final int maxDrain = 128;
188 List<SubstituteLoggingEvent> eventList = new ArrayList<SubstituteLoggingEvent>(maxDrain);
189 while (true) {
190 int numDrained = queue.drainTo(eventList, maxDrain);
191 if (numDrained == 0)
192 break;
193 for (SubstituteLoggingEvent event : eventList) {
194 replaySingleEvent(event);
195 if (count++ == 0)
196 emitReplayOrSubstituionWarning(event, queueSize);
197 }
198 eventList.clear();
199 }
200 }
201
202 private static void emitReplayOrSubstituionWarning(SubstituteLoggingEvent event, int queueSize) {
203 if (event.getLogger().isDelegateEventAware()) {
204 emitReplayWarning(queueSize);
205 } else if (event.getLogger().isDelegateNOP()) {
206 // nothing to do
207 } else {
208 emitSubstitutionWarning();
209 }
210 }
211
212 private static void replaySingleEvent(SubstituteLoggingEvent event) {
213 if (event == null)
180214 return;
181 }
182
215
216 SubstituteLogger substLogger = event.getLogger();
217 String loggerName = substLogger.getName();
218 if (substLogger.isDelegateNull()) {
219 Logger logger = getLogger(loggerName);
220 substLogger.setDelegate(logger);
221 }
222
223 if (substLogger.isDelegateNOP()) {
224 // nothing to do
225 } else if (substLogger.isDelegateEventAware()) {
226 substLogger.log(event);
227 } else {
228 Util.report(loggerName);
229 }
230 }
231
232 private static void emitSubstitutionWarning() {
183233 Util.report("The following set of substitute loggers may have been accessed");
184234 Util.report("during the initialization phase. Logging calls during this");
185235 Util.report("phase were not honored. However, subsequent logging calls to these");
186236 Util.report("loggers will work as normally expected.");
187237 Util.report("See also " + SUBSTITUTE_LOGGER_URL);
188 for (SubstituteLogger subLogger : loggers) {
189 subLogger.setDelegate(getLogger(subLogger.getName()));
190 Util.report(subLogger.getName());
191 }
192
193 TEMP_FACTORY.clear();
238 }
239
240 private static void emitReplayWarning(int eventCount) {
241 Util.report("A number (" + eventCount + ") of logging calls during the initialization phase have been intercepted and are");
242 Util.report("now being replayed. These are suject to the filtering rules of the underlying logging system.");
243 Util.report("See also " + REPLAY_URL);
194244 }
195245
196246 private final static void versionSanityCheck() {
245295 return staticLoggerBinderPathSet;
246296 }
247297
248 private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> staticLoggerBinderPathSet) {
249 return staticLoggerBinderPathSet.size() > 1;
298 private static boolean isAmbiguousStaticLoggerBinderPathSet(Set<URL> binderPathSet) {
299 return binderPathSet.size() > 1;
250300 }
251301
252302 /**
254304 * No reporting is done otherwise.
255305 *
256306 */
257 private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) {
258 if(isAndroid()) {
259 // skip check under android, see also http://jira.qos.ch/browse/SLF4J-328
260 return;
261 }
262
263 if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
307 private static void reportMultipleBindingAmbiguity(Set<URL> binderPathSet) {
308 if (isAmbiguousStaticLoggerBinderPathSet(binderPathSet)) {
264309 Util.report("Class path contains multiple SLF4J bindings.");
265 for (URL path : staticLoggerBinderPathSet) {
310 for (URL path : binderPathSet) {
266311 Util.report("Found binding in [" + path + "]");
267312 }
268313 Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation.");
271316
272317 private static boolean isAndroid() {
273318 String vendor = Util.safeGetSystemProperty(JAVA_VENDOR_PROPERTY);
274 if(vendor == null)
319 if (vendor == null)
275320 return false;
276321 return vendor.toLowerCase().contains("android");
277322 }
278323
279 private static void reportActualBinding(Set<URL> staticLoggerBinderPathSet) {
280 if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
324 private static void reportActualBinding(Set<URL> binderPathSet) {
325 // binderPathSet can be null under Android
326 if (binderPathSet != null && isAmbiguousStaticLoggerBinderPathSet(binderPathSet)) {
281327 Util.report("Actual binding is of type [" + StaticLoggerBinder.getSingleton().getLoggerFactoryClassStr() + "]");
282328 }
283329 }
354400 case ONGOING_INITIALIZATION:
355401 // support re-entrant behavior.
356402 // See also http://jira.qos.ch/browse/SLF4J-97
357 return TEMP_FACTORY;
403 return SUBST_FACTORY;
358404 }
359405 throw new IllegalStateException("Unreachable code");
360406 }
0 package org.slf4j.event;
1
2 import org.slf4j.spi.LocationAwareLogger;
3
4 public class EventConstants {
5 public static final int ERROR_INT = LocationAwareLogger.ERROR_INT;
6 public static final int WARN_INT = LocationAwareLogger.WARN_INT;
7 public static final int INFO_INT = LocationAwareLogger.INFO_INT;
8 public static final int DEBUG_INT = LocationAwareLogger.DEBUG_INT;
9 public static final int TRACE_INT = LocationAwareLogger.TRACE_INT;
10 public static final String NA_SUBST = "NA/SubstituteLogger";
11
12 }
0 package org.slf4j.event;
1
2 import java.util.Queue;
3
4 import org.slf4j.Logger;
5 import org.slf4j.Marker;
6 import org.slf4j.helpers.SubstituteLogger;
7
8 public class EventRecodingLogger implements Logger {
9
10 String name;
11 SubstituteLogger logger;
12 Queue<SubstituteLoggingEvent> eventQueue;
13
14 public EventRecodingLogger(SubstituteLogger logger, Queue<SubstituteLoggingEvent> eventQueue) {
15 this.logger = logger;
16 this.name = logger.getName();
17 this.eventQueue = eventQueue;
18 }
19
20 public String getName() {
21 return name;
22 }
23
24 private void recordEvent(Level level, String msg, Object[] args, Throwable throwable) {
25 recordEvent(level, null, msg, args, throwable);
26 }
27
28 private void recordEvent(Level level, Marker marker, String msg, Object[] args, Throwable throwable) {
29 // System.out.println("recording logger:"+name+", msg:"+msg);
30 SubstituteLoggingEvent loggingEvent = new SubstituteLoggingEvent();
31 loggingEvent.setTimeStamp(System.currentTimeMillis());
32 loggingEvent.setLevel(level);
33 loggingEvent.setLogger(logger);
34 loggingEvent.setLoggerName(name);
35
36 loggingEvent.setMessage(msg);
37 loggingEvent.setArgumentArray(args);
38 loggingEvent.setThrowable(throwable);
39 loggingEvent.setThreadName(Thread.currentThread().getName());
40 eventQueue.add(loggingEvent);
41 }
42
43 public boolean isTraceEnabled() {
44 return true;
45 }
46
47 public void trace(String msg) {
48 recordEvent(Level.TRACE, msg, null, null);
49 }
50
51 public void trace(String format, Object arg) {
52 recordEvent(Level.TRACE, format, new Object[] { arg }, null);
53 }
54
55 public void trace(String format, Object arg1, Object arg2) {
56 recordEvent(Level.TRACE, format, new Object[] { arg1, arg2 }, null);
57 }
58
59 public void trace(String format, Object... arguments) {
60 recordEvent(Level.TRACE, format, arguments, null);
61 }
62
63 public void trace(String msg, Throwable t) {
64 recordEvent(Level.TRACE, msg, null, t);
65 }
66
67 public boolean isTraceEnabled(Marker marker) {
68 return true;
69 }
70
71 public void trace(Marker marker, String msg) {
72 recordEvent(Level.TRACE, marker, msg, null, null);
73
74 }
75
76 public void trace(Marker marker, String format, Object arg) {
77 recordEvent(Level.TRACE, marker, format, new Object[] { arg }, null);
78 }
79
80 public void trace(Marker marker, String format, Object arg1, Object arg2) {
81 recordEvent(Level.TRACE, marker, format, new Object[] { arg1, arg2 }, null);
82 }
83
84 public void trace(Marker marker, String format, Object... argArray) {
85 recordEvent(Level.TRACE, marker, format, argArray, null);
86
87 }
88
89 public void trace(Marker marker, String msg, Throwable t) {
90 recordEvent(Level.TRACE, marker, msg, null, t);
91 }
92
93 public boolean isDebugEnabled() {
94 return true;
95 }
96
97 public void debug(String msg) {
98 recordEvent(Level.TRACE, msg, null, null);
99 }
100
101 public void debug(String format, Object arg) {
102 recordEvent(Level.DEBUG, format, new Object[] { arg }, null);
103
104 }
105
106 public void debug(String format, Object arg1, Object arg2) {
107 recordEvent(Level.DEBUG, format, new Object[] { arg1, arg2 }, null);
108
109 }
110
111 public void debug(String format, Object... arguments) {
112 recordEvent(Level.DEBUG, format, arguments, null);
113 }
114
115 public void debug(String msg, Throwable t) {
116 recordEvent(Level.DEBUG, msg, null, t);
117 }
118
119 public boolean isDebugEnabled(Marker marker) {
120 return true;
121 }
122
123 public void debug(Marker marker, String msg) {
124 recordEvent(Level.DEBUG, marker, msg, null, null);
125 }
126
127 public void debug(Marker marker, String format, Object arg) {
128 recordEvent(Level.DEBUG, marker, format, new Object[] { arg }, null);
129 }
130
131 public void debug(Marker marker, String format, Object arg1, Object arg2) {
132 recordEvent(Level.DEBUG, marker, format, new Object[] { arg1, arg2 }, null);
133 }
134
135 public void debug(Marker marker, String format, Object... arguments) {
136 recordEvent(Level.DEBUG, marker, format, arguments, null);
137 }
138
139 public void debug(Marker marker, String msg, Throwable t) {
140 recordEvent(Level.DEBUG, marker, msg, null, t);
141 }
142
143 public boolean isInfoEnabled() {
144 return true;
145 }
146
147 public void info(String msg) {
148 recordEvent(Level.INFO, msg, null, null);
149 }
150
151 public void info(String format, Object arg) {
152 recordEvent(Level.INFO, format, new Object[] { arg }, null);
153 }
154
155 public void info(String format, Object arg1, Object arg2) {
156 recordEvent(Level.INFO, format, new Object[] { arg1, arg2 }, null);
157 }
158
159 public void info(String format, Object... arguments) {
160 recordEvent(Level.INFO, format, arguments, null);
161 }
162
163 public void info(String msg, Throwable t) {
164 recordEvent(Level.INFO, msg, null, t);
165 }
166
167 public boolean isInfoEnabled(Marker marker) {
168 return true;
169 }
170
171 public void info(Marker marker, String msg) {
172 recordEvent(Level.INFO, marker, msg, null, null);
173 }
174
175 public void info(Marker marker, String format, Object arg) {
176 recordEvent(Level.INFO, marker, format, new Object[] { arg }, null);
177 }
178
179 public void info(Marker marker, String format, Object arg1, Object arg2) {
180 recordEvent(Level.INFO, marker, format, new Object[] { arg1, arg2 }, null);
181 }
182
183 public void info(Marker marker, String format, Object... arguments) {
184 recordEvent(Level.INFO, marker, format, arguments, null);
185 }
186
187 public void info(Marker marker, String msg, Throwable t) {
188 recordEvent(Level.INFO, marker, msg, null, t);
189
190 }
191
192 public boolean isWarnEnabled() {
193 return true;
194 }
195
196 public void warn(String msg) {
197 recordEvent(Level.WARN, msg, null, null);
198 }
199
200 public void warn(String format, Object arg) {
201 recordEvent(Level.WARN, format, new Object[] { arg }, null);
202
203 }
204
205 public void warn(String format, Object arg1, Object arg2) {
206 recordEvent(Level.WARN, format, new Object[] { arg1, arg2 }, null);
207 }
208
209 public void warn(String format, Object... arguments) {
210 recordEvent(Level.WARN, format, arguments, null);
211 }
212
213 public void warn(String msg, Throwable t) {
214 recordEvent(Level.WARN, msg, null, t);
215 }
216
217 public boolean isWarnEnabled(Marker marker) {
218 return true;
219 }
220
221 public void warn(Marker marker, String msg) {
222 recordEvent(Level.WARN, msg, null, null);
223 }
224
225 public void warn(Marker marker, String format, Object arg) {
226 recordEvent(Level.WARN, format, new Object[] { arg }, null);
227 }
228
229 public void warn(Marker marker, String format, Object arg1, Object arg2) {
230 recordEvent(Level.WARN, marker, format, new Object[] { arg1, arg2 }, null);
231
232 }
233
234 public void warn(Marker marker, String format, Object... arguments) {
235 recordEvent(Level.WARN, marker, format, arguments, null);
236 }
237
238 public void warn(Marker marker, String msg, Throwable t) {
239 recordEvent(Level.WARN, marker, msg, null, t);
240 }
241
242 public boolean isErrorEnabled() {
243 return true;
244 }
245
246 public void error(String msg) {
247 recordEvent(Level.ERROR, msg, null, null);
248 }
249
250 public void error(String format, Object arg) {
251 recordEvent(Level.ERROR, format, new Object[] { arg }, null);
252
253 }
254
255 public void error(String format, Object arg1, Object arg2) {
256 recordEvent(Level.ERROR, format, new Object[] { arg1, arg2 }, null);
257
258 }
259
260 public void error(String format, Object... arguments) {
261 recordEvent(Level.ERROR, format, arguments, null);
262
263 }
264
265 public void error(String msg, Throwable t) {
266 recordEvent(Level.ERROR, msg, null, t);
267 }
268
269 public boolean isErrorEnabled(Marker marker) {
270 return true;
271 }
272
273 public void error(Marker marker, String msg) {
274 recordEvent(Level.ERROR, marker, msg, null, null);
275
276 }
277
278 public void error(Marker marker, String format, Object arg) {
279 recordEvent(Level.ERROR, marker, format, new Object[] { arg }, null);
280
281 }
282
283 public void error(Marker marker, String format, Object arg1, Object arg2) {
284 recordEvent(Level.ERROR, marker, format, new Object[] { arg1, arg2 }, null);
285 }
286
287 public void error(Marker marker, String format, Object... arguments) {
288 recordEvent(Level.ERROR, marker, format, arguments, null);
289 }
290
291 public void error(Marker marker, String msg, Throwable t) {
292 recordEvent(Level.ERROR, marker, msg, null, t);
293 }
294
295 }
0 package org.slf4j.event;
1
2 import static org.slf4j.event.EventConstants.DEBUG_INT;
3 import static org.slf4j.event.EventConstants.ERROR_INT;
4 import static org.slf4j.event.EventConstants.INFO_INT;
5 import static org.slf4j.event.EventConstants.TRACE_INT;
6 import static org.slf4j.event.EventConstants.WARN_INT;
7
8 /**
9 *
10 * @author ceki
11 * @since 1.7.15
12 */
13 public enum Level {
14
15 ERROR(ERROR_INT, "ERROR"), WARN(WARN_INT, "WARN"), INFO(INFO_INT, "INFO"), DEBUG(DEBUG_INT, "DEBUG"), TRACE(TRACE_INT, "TRACE");
16
17 private int levelInt;
18 private String levelStr;
19
20 Level(int i, String s) {
21 levelInt = i;
22 levelStr = s;
23 }
24
25 public int toInt() {
26 return levelInt;
27 }
28
29 /**
30 * Returns the string representation of this Level.
31 */
32 public String toString() {
33 return levelStr;
34 }
35
36 }
0 package org.slf4j.event;
1
2 import org.slf4j.Marker;
3
4 /**
5 *
6 * @author ceki
7 * @since 1.7.15
8 */
9 public interface LoggingEvent {
10
11 Level getLevel();
12
13 Marker getMarker();
14
15 String getLoggerName();
16
17 String getMessage();
18
19 String getThreadName();
20
21 Object[] getArgumentArray();
22
23 long getTimeStamp();
24
25 Throwable getThrowable();
26
27 }
0 package org.slf4j.event;
1
2 import org.slf4j.Marker;
3 import org.slf4j.helpers.SubstituteLogger;
4
5 public class SubstituteLoggingEvent implements LoggingEvent {
6
7 Level level;
8 Marker marker;
9 String loggerName;
10 SubstituteLogger logger;
11 String threadName;
12 String message;
13 Object[] argArray;
14 long timeStamp;
15 Throwable throwable;
16
17 public Level getLevel() {
18 return level;
19 }
20
21 public void setLevel(Level level) {
22 this.level = level;
23 }
24
25 public Marker getMarker() {
26 return marker;
27 }
28
29 public void setMarker(Marker marker) {
30 this.marker = marker;
31 }
32
33 public String getLoggerName() {
34 return loggerName;
35 }
36
37 public void setLoggerName(String loggerName) {
38 this.loggerName = loggerName;
39 }
40
41 public SubstituteLogger getLogger() {
42 return logger;
43 }
44
45 public void setLogger(SubstituteLogger logger) {
46 this.logger = logger;
47 }
48
49 public String getMessage() {
50 return message;
51 }
52
53 public void setMessage(String message) {
54 this.message = message;
55 }
56
57 public Object[] getArgumentArray() {
58 return argArray;
59 }
60
61 public void setArgumentArray(Object[] argArray) {
62 this.argArray = argArray;
63 }
64
65 public long getTimeStamp() {
66 return timeStamp;
67 }
68
69 public void setTimeStamp(long timeStamp) {
70 this.timeStamp = timeStamp;
71 }
72
73 public String getThreadName() {
74 return threadName;
75 }
76
77 public void setThreadName(String threadName) {
78 this.threadName = threadName;
79 }
80
81 public Throwable getThrowable() {
82 return throwable;
83 }
84
85 public void setThrowable(Throwable throwable) {
86 this.throwable = throwable;
87 }
88 }
4343 */
4444 public class BasicMDCAdapter implements MDCAdapter {
4545
46 private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal =
47 new InheritableThreadLocal<Map<String, String>>() {
46 private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal = new InheritableThreadLocal<Map<String, String>>() {
4847 @Override
49 protected Map<String,String> childValue(Map<String,String> parentValue) {
48 protected Map<String, String> childValue(Map<String, String> parentValue) {
5049 if (parentValue == null) {
5150 return null;
5251 }
4343 public FormattingTuple(String message, Object[] argArray, Throwable throwable) {
4444 this.message = message;
4545 this.throwable = throwable;
46 if (throwable == null) {
47 this.argArray = argArray;
48 } else {
49 this.argArray = trimmedCopy(argArray);
50 }
51 }
52
53 static Object[] trimmedCopy(Object[] argArray) {
54 if (argArray == null || argArray.length == 0) {
55 throw new IllegalStateException("non-sensical empty or null argument array");
56 }
57 final int trimemdLen = argArray.length - 1;
58 Object[] trimmed = new Object[trimemdLen];
59 System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
60 return trimmed;
46 this.argArray = argArray;
6147 }
6248
6349 public String getMessage() {
3232 /**
3333 * Formats messages according to very simple substitution rules. Substitutions
3434 * can be made 1, 2 or more arguments.
35 *
35 *
3636 * <p>
3737 * For example,
38 *
38 *
3939 * <pre>
4040 * MessageFormatter.format(&quot;Hi {}.&quot;, &quot;there&quot;)
4141 * </pre>
42 *
42 *
4343 * will return the string "Hi there.".
4444 * <p>
4545 * The {} pair is called the <em>formatting anchor</em>. It serves to designate
4949 * In case your message contains the '{' or the '}' character, you do not have
5050 * to do anything special unless the '}' character immediately follows '{'. For
5151 * example,
52 *
52 *
5353 * <pre>
5454 * MessageFormatter.format(&quot;Set {1,2,3} is not equal to {}.&quot;, &quot;1,2&quot;);
5555 * </pre>
56 *
56 *
5757 * will return the string "Set {1,2,3} is not equal to 1,2.".
58 *
58 *
5959 * <p>
6060 * If for whatever reason you need to place the string "{}" in the message
6161 * without its <em>formatting anchor</em> meaning, then you need to escape the
6262 * '{' character with '\', that is the backslash character. Only the '{'
6363 * character should be escaped. There is no need to escape the '}' character.
6464 * For example,
65 *
65 *
6666 * <pre>
6767 * MessageFormatter.format(&quot;Set \\{} is not equal to {}.&quot;, &quot;1,2&quot;);
6868 * </pre>
69 *
69 *
7070 * will return the string "Set {} is not equal to 1,2.".
71 *
71 *
7272 * <p>
7373 * The escaping behavior just described can be overridden by escaping the escape
7474 * character '\'. Calling
75 *
75 *
7676 * <pre>
7777 * MessageFormatter.format(&quot;File name is C:\\\\{}.&quot;, &quot;file.zip&quot;);
7878 * </pre>
79 *
79 *
8080 * will return the string "File name is C:\file.zip".
81 *
81 *
8282 * <p>
8383 * The formatting conventions are different than those of {@link MessageFormat}
8484 * which ships with the Java platform. This is justified by the fact that
8585 * SLF4J's implementation is 10 times faster than that of {@link MessageFormat}.
8686 * This local performance difference is both measurable and significant in the
8787 * larger context of the complete logging processing chain.
88 *
88 *
8989 * <p>
9090 * See also {@link #format(String, Object)},
9191 * {@link #format(String, Object, Object)} and
9292 * {@link #arrayFormat(String, Object[])} methods for more details.
93 *
93 *
9494 * @author Ceki G&uuml;lc&uuml;
9595 * @author Joern Huxhorn
9696 */
105105 * parameter.
106106 * <p>
107107 * For example,
108 *
108 *
109109 * <pre>
110110 * MessageFormatter.format(&quot;Hi {}.&quot;, &quot;there&quot;);
111111 * </pre>
112 *
112 *
113113 * will return the string "Hi there.".
114114 * <p>
115 *
115 *
116116 * @param messagePattern
117117 * The message pattern which will be parsed and formatted
118 * @param argument
118 * @param arg
119119 * The argument to be substituted in place of the formatting anchor
120120 * @return The formatted message
121121 */
124124 }
125125
126126 /**
127 *
127 *
128128 * Performs a two argument substitution for the 'messagePattern' passed as
129129 * parameter.
130130 * <p>
131131 * For example,
132 *
132 *
133133 * <pre>
134134 * MessageFormatter.format(&quot;Hi {}. My name is {}.&quot;, &quot;Alice&quot;, &quot;Bob&quot;);
135135 * </pre>
136 *
136 *
137137 * will return the string "Hi Alice. My name is Bob.".
138 *
138 *
139139 * @param messagePattern
140140 * The message pattern which will be parsed and formatted
141141 * @param arg1
150150 return arrayFormat(messagePattern, new Object[] { arg1, arg2 });
151151 }
152152
153
153154 static final Throwable getThrowableCandidate(Object[] argArray) {
154155 if (argArray == null || argArray.length == 0) {
155156 return null;
162163 return null;
163164 }
164165
165 /**
166 * Same principle as the {@link #format(String, Object)} and
167 * {@link #format(String, Object, Object)} methods except that any number of
168 * arguments can be passed in an array.
169 *
170 * @param messagePattern
171 * The message pattern which will be parsed and formatted
172 * @param argArray
173 * An array of arguments to be substituted in place of formatting
174 * anchors
175 * @return The formatted message
176 */
177166 final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
178
179167 Throwable throwableCandidate = getThrowableCandidate(argArray);
168 Object[] args = argArray;
169 if (throwableCandidate != null) {
170 args = trimmedCopy(argArray);
171 }
172 return arrayFormat(messagePattern, args, throwableCandidate);
173 }
174
175 private static Object[] trimmedCopy(Object[] argArray) {
176 if (argArray == null || argArray.length == 0) {
177 throw new IllegalStateException("non-sensical empty or null argument array");
178 }
179 final int trimemdLen = argArray.length - 1;
180 Object[] trimmed = new Object[trimemdLen];
181 System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
182 return trimmed;
183 }
184
185 final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray, Throwable throwable) {
180186
181187 if (messagePattern == null) {
182 return new FormattingTuple(null, argArray, throwableCandidate);
188 return new FormattingTuple(null, argArray, throwable);
183189 }
184190
185191 if (argArray == null) {
199205 if (j == -1) {
200206 // no more variables
201207 if (i == 0) { // this is a simple string
202 return new FormattingTuple(messagePattern, argArray, throwableCandidate);
208 return new FormattingTuple(messagePattern, argArray, throwable);
203209 } else { // add the tail string which contains no variables and return
204210 // the result.
205211 sbuf.append(messagePattern, i, messagePattern.length());
206 return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
212 return new FormattingTuple(sbuf.toString(), argArray, throwable);
207213 }
208214 } else {
209215 if (isEscapedDelimeter(messagePattern, j)) {
230236 }
231237 // append the characters following the last {} pair.
232238 sbuf.append(messagePattern, i, messagePattern.length());
233 if (L < argArray.length - 1) {
234 return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
235 } else {
236 return new FormattingTuple(sbuf.toString(), argArray, null);
237 }
239 return new FormattingTuple(sbuf.toString(), argArray, throwable);
238240 }
239241
240242 final static boolean isEscapedDelimeter(String messagePattern, int delimeterStartIndex) {
296298 String oAsString = o.toString();
297299 sbuf.append(oAsString);
298300 } catch (Throwable t) {
299 System.err.println("SLF4J: Failed toString() invocation on an object of type [" + o.getClass().getName() + "]");
300 t.printStackTrace();
301 Util.report("SLF4J: Failed toString() invocation on an object of type [" + o.getClass().getName() + "]", t);
301302 sbuf.append("[FAILED toString()]");
302303 }
303304
408409 }
409410 sbuf.append(']');
410411 }
412
411413 }
2323 */
2424 package org.slf4j.helpers;
2525
26 import java.lang.reflect.InvocationTargetException;
27 import java.lang.reflect.Method;
28 import java.util.Queue;
29
2630 import org.slf4j.Logger;
2731 import org.slf4j.Marker;
32 import org.slf4j.event.EventRecodingLogger;
33 import org.slf4j.event.LoggingEvent;
34 import org.slf4j.event.SubstituteLoggingEvent;
2835
2936 /**
3037 * A logger implementation which logs via a delegate logger. By default, the delegate is a
31 * {@link NOPLogger}. However, a different delegate can be set at anytime.
38 * {@link NOPLogger}. However, a different delegate can be set at any time.
3239 * <p/>
3340 * See also the <a href="http://www.slf4j.org/codes.html#substituteLogger">relevant
3441 * error code</a> documentation.
3542 *
3643 * @author Chetan Mehrotra
44 * @author Ceki Gulcu
3745 */
3846 public class SubstituteLogger implements Logger {
3947
4048 private final String name;
41
4249 private volatile Logger _delegate;
43
44 public SubstituteLogger(String name) {
50 private Boolean delegateEventAware;
51 private Method logMethodCache;
52 private EventRecodingLogger eventRecodingLogger;
53 private Queue<SubstituteLoggingEvent> eventQueue;
54
55 public SubstituteLogger(String name, Queue<SubstituteLoggingEvent> eventQueue) {
4556 this.name = name;
57 this.eventQueue = eventQueue;
4658 }
4759
4860 public String getName() {
314326 * instance.
315327 */
316328 Logger delegate() {
317 return _delegate != null ? _delegate : NOPLogger.NOP_LOGGER;
329 return _delegate != null ? _delegate : getEventRecordingLogger();
330 }
331
332 private Logger getEventRecordingLogger() {
333 if (eventRecodingLogger == null) {
334 eventRecodingLogger = new EventRecodingLogger(this, eventQueue);
335 }
336 return eventRecodingLogger;
318337 }
319338
320339 /**
324343 public void setDelegate(Logger delegate) {
325344 this._delegate = delegate;
326345 }
346
347 public boolean isDelegateEventAware() {
348 if (delegateEventAware != null)
349 return delegateEventAware;
350
351 try {
352 logMethodCache = _delegate.getClass().getMethod("log", LoggingEvent.class);
353 delegateEventAware = Boolean.TRUE;
354 } catch (NoSuchMethodException e) {
355 delegateEventAware = Boolean.FALSE;
356 }
357 return delegateEventAware;
358 }
359
360 public void log(LoggingEvent event) {
361 if (isDelegateEventAware()) {
362 try {
363 logMethodCache.invoke(_delegate, event);
364 } catch (IllegalAccessException e) {
365 } catch (IllegalArgumentException e) {
366 } catch (InvocationTargetException e) {
367 }
368 }
369 }
370
371
372 public boolean isDelegateNull() {
373 return _delegate == null;
374 }
375
376 public boolean isDelegateNOP() {
377 return _delegate instanceof NOPLogger;
378 }
327379 }
2323 */
2424 package org.slf4j.helpers;
2525
26 import org.slf4j.ILoggerFactory;
27 import org.slf4j.Logger;
28
2926 import java.util.ArrayList;
3027 import java.util.List;
3128 import java.util.concurrent.ConcurrentHashMap;
3229 import java.util.concurrent.ConcurrentMap;
30 import java.util.concurrent.LinkedBlockingQueue;
31
32 import org.slf4j.ILoggerFactory;
33 import org.slf4j.Logger;
34 import org.slf4j.event.SubstituteLoggingEvent;
3335
3436 /**
3537 * SubstituteLoggerFactory manages instances of {@link SubstituteLogger}.
4143
4244 final ConcurrentMap<String, SubstituteLogger> loggers = new ConcurrentHashMap<String, SubstituteLogger>();
4345
46 final LinkedBlockingQueue<SubstituteLoggingEvent> eventQueue = new LinkedBlockingQueue<SubstituteLoggingEvent>();
47
4448 public Logger getLogger(String name) {
4549 SubstituteLogger logger = loggers.get(name);
4650 if (logger == null) {
47 logger = new SubstituteLogger(name);
51 logger = new SubstituteLogger(name, eventQueue);
4852 SubstituteLogger oldLogger = loggers.putIfAbsent(name, logger);
4953 if (oldLogger != null)
5054 logger = oldLogger;
6064 return new ArrayList<SubstituteLogger>(loggers.values());
6165 }
6266
67 public LinkedBlockingQueue<SubstituteLoggingEvent> getEventQueue() {
68 return eventQueue;
69 }
70
6371 public void clear() {
6472 loggers.clear();
73 eventQueue.clear();
6574 }
6675 }
6868
6969 private static ClassContextSecurityManager SECURITY_MANAGER;
7070 private static boolean SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = false;
71
71
7272 private static ClassContextSecurityManager getSecurityManager() {
73 if(SECURITY_MANAGER != null)
73 if (SECURITY_MANAGER != null)
7474 return SECURITY_MANAGER;
75 else if(SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED)
75 else if (SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED)
7676 return null;
7777 else {
78 SECURITY_MANAGER = safeCreateSecurityManager();
78 SECURITY_MANAGER = safeCreateSecurityManager();
7979 SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = true;
8080 return SECURITY_MANAGER;
8181 }
8282 }
83
83
8484 private static ClassContextSecurityManager safeCreateSecurityManager() {
8585 try {
8686 return new ClassContextSecurityManager();
9696 */
9797 public static Class<?> getCallingClass() {
9898 ClassContextSecurityManager securityManager = getSecurityManager();
99 if(securityManager == null)
99 if (securityManager == null)
100100 return null;
101101 Class<?>[] trace = securityManager.getClassContext();
102102 String thisClassName = Util.class.getName();
2626 import org.slf4j.ILoggerFactory;
2727
2828 /**
29 * The binding of {@link LoggerFactory} class with an actual instance of
29 * The binding of {@link org.slf4j.LoggerFactory} class with an actual instance of
3030 * {@link ILoggerFactory} is performed using information returned by this class.
31 *
32 * This class is meant to provide a dummy StaticLoggerBinder to the slf4j-api module.
33 * Real implementations are found in each SLF4J binding project, e.g. slf4j-nop,
31 *
32 * This class is meant to provide a dummy StaticLoggerBinder to the slf4j-api module.
33 * Real implementations are found in each SLF4J binding project, e.g. slf4j-nop,
3434 * slf4j-log4j12 etc.
35 *
35 *
3636 * @author Ceki G&uuml;lc&uuml;
3737 */
3838 public class StaticLoggerBinder {
4444
4545 /**
4646 * Return the singleton of this class.
47 *
47 *
4848 * @return the StaticLoggerBinder singleton
4949 */
5050 public static final StaticLoggerBinder getSingleton() {
5252 }
5353
5454 /**
55 * Declare the version of the SLF4J API this implementation is compiled against.
56 * The value of this field is modified with each major release.
55 * Declare the version of the SLF4J API this implementation is compiled against.
56 * The value of this field is modified with each major release.
5757 */
5858 // to avoid constant folding by the compiler, this field must *not* be final
5959 public static String REQUESTED_API_VERSION = "1.6.99"; // !final
4141 private StaticMDCBinder() {
4242 throw new UnsupportedOperationException("This code should never make it into the jar");
4343 }
44
44
4545 /**
4646 * Return the singleton of this class.
4747 *
4949 * @since 1.7.14
5050 */
5151 public static final StaticMDCBinder getSingleton() {
52 return SINGLETON;
52 return SINGLETON;
5353 }
5454
5555 /**
5959 public static StaticMarkerBinder getSingleton() {
6060 return SINGLETON;
6161 }
62
62
6363 /**
6464 * Currently this method always returns an instance of
6565 * {@link BasicMarkerFactory}.
3838 */
3939 public interface LocationAwareLogger extends Logger {
4040
41 // these constants should be in EventContants. However, in order to preserve binary backward compatibility
42 // we keep these constants here
4143 final public int TRACE_INT = 00;
4244 final public int DEBUG_INT = 10;
4345 final public int INFO_INT = 20;
33 Bundle-Name: slf4j-api
44 Bundle-Vendor: SLF4J.ORG
55 Bundle-RequiredExecutionEnvironment: J2SE-1.5
6 Export-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}, org.slf4j.helpers;version=${parsedVersion.osgiVersion}
6 Export-Package: org.slf4j;version=${parsedVersion.osgiVersion},
7 org.slf4j.spi;version=${parsedVersion.osgiVersion},
8 org.slf4j.helpers;version=${parsedVersion.osgiVersion},
9 org.slf4j.event;version=${parsedVersion.osgiVersion}
710 Import-Package: org.slf4j.impl;version=${slf4j.api.minimum.compatible.version}
3636 * @author Ceki G&uuml;lc&uuml;
3737 * @author Joern Huxhorn
3838 */
39 public class BasicMarkerTest {
39 public class BasicMarkerTest {
4040 static final String BLUE_STR = "BLUE";
4141 static final String RED_STR = "RED";
4242 static final String GREEN_STR = "GREEN";
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 }
+0
-55
slf4j-api/src/test/java/org/slf4j/FindStaticLoggerBinderPathsPerfTest.java less more
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 }
4444 }
4545
4646 @Test
47 public void testMDC() {
47 public void testMDC() {
4848 MDC.put("k" + diff, "v");
4949 assertNull(MDC.get("k"));
5050 }
4040 *
4141 * @author Lukasz Cwik
4242 */
43 public class BasicMDCAdapterTest {
43 public class BasicMDCAdapterTest {
4444 MDCAdapter mdc = new BasicMDCAdapter();
4545
4646 @After
5454 mdc.put("testKey", "testValue");
5555 assertEquals(mdc.get("testKey"), "testValue");
5656 }
57
57
5858 @Test
5959 public void testOverwritingAKeyInMDC() {
6060 assertNull(mdc.get("testKey"));
2929 import org.junit.Test;
3030
3131 @Ignore
32 public class MessageFormatterPerfTest{ //extends TestCase {
32 public class MessageFormatterPerfTest { // extends TestCase {
3333
3434 Integer i1 = new Integer(1);
3535 Integer i2 = new Integer(2);
310310 assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
311311 assertEquals(t, ft.getThrowable());
312312
313 ft = MessageFormatter.arrayFormat("Value {} is smaller than {} and {} -- {} .", ia);
314 assertEquals("Value 1 is smaller than 2 and 3 -- " + t.toString() + " .", ft.getMessage());
315 assertTrue(Arrays.equals(ia, ft.getArgArray()));
316 assertNull(ft.getThrowable());
313 ft = MessageFormatter.arrayFormat("Value {} is smaller than {} and {}.", ia);
314 assertEquals("Value 1 is smaller than 2 and 3.", ft.getMessage());
315 assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
316 assertEquals(t, ft.getThrowable());
317317
318318 ft = MessageFormatter.arrayFormat("{}{}{}{}", ia);
319 assertEquals("123" + t.toString(), ft.getMessage());
320 assertTrue(Arrays.equals(ia, ft.getArgArray()));
321 assertNull(ft.getThrowable());
319 assertEquals("123{}", ft.getMessage());
320 assertTrue(Arrays.equals(iaWitness, ft.getArgArray()));
321 assertEquals(t, ft.getThrowable());
322
323 ft = MessageFormatter.arrayFormat("1={}", new Object[] { i1 }, t);
324 assertEquals("1=1", ft.getMessage());
325 assertTrue(Arrays.equals(new Object[] { i1 }, ft.getArgArray()));
326 assertEquals(t, ft.getThrowable());
327
322328 }
323329 }
3838
3939 import org.junit.Test;
4040 import org.slf4j.Logger;
41 import org.slf4j.event.EventRecodingLogger;
4142
4243 /**
4344 * @author Chetan Mehrotra
4748
4849 @Test
4950 public void testDelegate() throws Exception {
50 SubstituteLogger log = new SubstituteLogger("foo");
51 assertTrue(log.delegate() instanceof NOPLogger);
51 SubstituteLogger log = new SubstituteLogger("foo", null);
52 assertTrue(log.delegate() instanceof EventRecodingLogger);
5253
5354 Set<String> expectedMethodSignatures = determineMethodSignatures(Logger.class);
5455 LoggerInvocationHandler ih = new LoggerInvocationHandler();
3434 import java.util.HashSet;
3535 import java.util.Set;
3636
37 public class SubstituteLoggerFactoryTest {
37 public class SubstituteLoggerFactoryTest {
3838 private SubstituteLoggerFactory factory = new SubstituteLoggerFactory();
3939
4040 @Test
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-ext</artifactId>
3333
3434 /**
3535 * Entry point for slf4j-ext when used as a Java agent.
36 *
36 *
3737 */
3838 public class AgentPremain {
3939
4040 /**
4141 * JavaAgent premain entry point as specified in the MANIFEST.MF file. See
42 * {@link http
43 * ://java.sun.com/javase/6/docs/api/java/lang/instrument/package-
44 * summary.html} for details.
45 *
42 * <a href="http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html">http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html</a> for details.
43 *
4644 * @param agentArgument
4745 * string provided after "=" up to first space
4846 * @param instrumentation
8482 * Consider the argument string to be a property file (by converting the
8583 * splitter character to line feeds), and then reading it like any other
8684 * property file.
87 *
88 *
85 *
86 *
8987 * @param agentArgument
9088 * string given by instrumentation framework
9189 * @param separator
108106 * Print the start message to System.err with the time NOW, and register a
109107 * shutdown hook which will print the stop message to System.err with the
110108 * time then and the number of milliseconds passed since.
111 *
109 *
112110 */
113111 private static void printStartStopTimes() {
114112 final long start = System.currentTimeMillis();
124122 };
125123 Runtime.getRuntime().addShutdownHook(hook);
126124 }
127 }
125 }
2929 import ch.qos.cal10n.IMessageConveyor;
3030
3131 /**
32 *
32 *
3333 * This class is essentially a wrapper around an {@link LoggerFactory} producing
3434 * {@link LocLogger} instances.
35 *
35 *
3636 * <p>
3737 * Contrary to {@link LoggerFactory#getLogger(String)} method of
38 * {@link LoggerFactory}, each call to {@link getLocLogger} produces a new
38 * {@link LoggerFactory}, each call to {@link #getLocLogger(String)} produces a new
3939 * instance of {@link LocLogger}. This should not matter because a LocLogger
40 * instance does have any state beyond that of the {@link Logger} in stance it
40 * instance does have any state beyond that of the {@link Logger} instance it
4141 * wraps and its message conveyor.
42 *
42 *
4343 * @author Ceki G&uuml;c&uuml;
44 *
44 *
4545 */
4646 public class LocLoggerFactory {
4747
5353
5454 /**
5555 * Get an LocLogger instance by name.
56 *
56 *
5757 * @param name
5858 * @return LocLogger instance by name.
5959 */
6464 /**
6565 * Get a new LocLogger instance by class. The returned LocLogger will be named
6666 * after the class.
67 *
67 *
6868 * @param clazz
6969 * @return LocLogger instance by class
7070 */
2222 *
2323 */
2424 /**
25 *
25 *
2626 */
2727 package org.slf4j.instrumentation;
2828
5656 /**
5757 * Builder provides a flexible way of configuring some of many options on the
5858 * parent class instead of providing many constructors.
59 *
60 * {@link http
61 * ://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html}
62 *
59 *
60 * <a href="http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html">http://rwhansen.blogspot.com/2007/07/theres-builder-pattern-that-joshua.html</a>
61 *
6362 */
6463 public static class Builder {
6564
6665 /**
6766 * Build and return the LogTransformer corresponding to the options set in
6867 * this Builder.
69 *
68 *
7069 * @return
7170 */
7271 public LogTransformer build() {
8180 /**
8281 * Should each method log entry (with parameters) and exit (with parameters
8382 * and returnvalue)?
84 *
83 *
8584 * @param b
8685 * value of flag
8786 * @return
104103 /**
105104 * Should LogTransformer be verbose in what it does? This currently list the
106105 * names of the classes being processed.
107 *
106 *
108107 * @param b
109108 * @return
110109 */
176175 * transform0 sees if the className starts with any of the namespaces to
177176 * ignore, if so it is returned unchanged. Otherwise it is processed by
178177 * doClass(...)
179 *
178 *
180179 * @param className
181180 * @param clazz
182181 * @param domain
226225 * defined have bodies, and a static final logger object is added with the
227226 * name of this class as an argument, and each method then gets processed with
228227 * doMethod(...) to have logger calls added.
229 *
228 *
230229 * @param name
231230 * class name (slashes separate, not dots)
232231 * @param clazz
284283 /**
285284 * process a single method - this means add entry/exit logging if requested.
286285 * It is only called for methods with a body.
287 *
286 *
288287 * @param method
289288 * method to work on
290289 * @throws NotFoundException
309308 method.insertAfter(after);
310309 }
311310 }
312 }
311 }
4040 assertEquals("", NDC.pop());
4141 }
4242
43
4443 @Test
4544 public void testSmoke() {
4645 NDC.push("a");
4746 String result = NDC.pop();
4847 assertEquals("a", result);
4948 }
50
5149
5250 @Test
5351 public void testSmoke2() {
3636
3737 import ch.qos.cal10n.IMessageConveyor;
3838 import ch.qos.cal10n.MessageConveyor;
39 public class LocLoggerTest {
39
40 public class LocLoggerTest {
4041
4142 ListAppender listAppender;
4243 org.apache.log4j.Logger log4jRoot;
4546 LocLoggerFactory llFactory_uk = new LocLoggerFactory(imc);
4647
4748 final static String EXPECTED_FILE_NAME = "LocLoggerTest.java";
48
4949
5050 @Before
5151 public void setUp() throws Exception {
6363 assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
6464 }
6565
66
6766 @Test
6867 public void testSmoke() {
6968 LocLogger locLogger = llFactory_uk.getLocLogger(this.getClass());
3737 import org.slf4j.MDC;
3838 import org.slf4j.ext.EventData;
3939 import org.slf4j.ext.EventLogger;
40 public class EventLoggerTest {
40
41 public class EventLoggerTest {
4142
4243 ListAppender listAppender;
4344 org.apache.log4j.Logger log4;
4445
4546 final static String EXPECTED_FILE_NAME = "EventLoggerTest.java";
46
4747
4848 @Before
4949 public void setUp() throws Exception {
7575 assertEquals(expectedMsg, le.getMessage());
7676 assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
7777 }
78
78
7979 @Test
8080 public void testEventLogger() {
8181 EventData data[] = new EventData[2];
2828 import org.junit.Test;
2929 import org.slf4j.MDC;
3030 import org.slf4j.ext.MDCStrLookup;
31 public class MDCStrLookupTest {
31
32 public class MDCStrLookupTest {
3233
3334 @Test
3435 public void testLookup() throws Exception {
2323 */
2424 package org.slf4j.dummyExt;
2525
26 import junit.framework.*;
27
2826 import org.junit.runner.RunWith;
2927 import org.junit.runners.Suite;
3028 import org.junit.runners.Suite.SuiteClasses;
2727
2828 import org.junit.Test;
2929
30 public class ToStringHelperTest {
30 public class ToStringHelperTest {
3131
3232 @Test
3333 public void testRenderer() {
2828 import org.junit.runners.Suite.SuiteClasses;
2929
3030 @RunWith(Suite.class)
31 @SuiteClasses({UtilTest.class,
32 ProfilerTest.class})
31 @SuiteClasses({ UtilTest.class, ProfilerTest.class })
3332 public class PackageTest {
3433
35
3634 }
3030 import org.junit.Test;
3131 import org.slf4j.Logger;
3232 import org.slf4j.LoggerFactory;
33
3334 public class ProfilerTest {
3435
3536 Logger logger = LoggerFactory.getLogger(ProfilerTest.class);
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jcl</artifactId>
5656 // to avoid constant folding by the compiler, this field must *not* be final
5757 public static String REQUESTED_API_VERSION = "1.6.99"; // !final
5858
59
6059 // Binding specific code:
6160 private static final String loggerFactoryClassStr = JCLLoggerFactory.class.getName();
6261
5656 public static StaticMarkerBinder getSingleton() {
5757 return SINGLETON;
5858 }
59
59
6060 /**
6161 * Currently this method always returns an instance of
6262 * {@link BasicMarkerFactory}.
4141
4242 Level oldLevel;
4343 java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
44
4544
4645 @Before
4746 public void setUp() throws Exception {
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-jdk14</artifactId>
2828
2929 import org.slf4j.Logger;
3030 import org.slf4j.Marker;
31 import org.slf4j.event.EventConstants;
32 import org.slf4j.event.LoggingEvent;
3133 import org.slf4j.helpers.FormattingTuple;
3234 import org.slf4j.helpers.MarkerIgnoringBase;
3335 import org.slf4j.helpers.MessageFormatter;
573575 LogRecord record = new LogRecord(level, msg);
574576 record.setLoggerName(getName());
575577 record.setThrown(t);
576 // Note: parameters in record are not set because SLF4J only
578 // Note: parameters in record are not set because SLF4J only
577579 // supports a single formatting style
578580 fillCallerData(callerFQCN, record);
579581 logger.log(record);
580
581582 }
582583
583584 static String SELF = JDK14LoggerAdapter.class.getName();
620621 }
621622
622623 public void log(Marker marker, String callerFQCN, int level, String message, Object[] argArray, Throwable t) {
624 Level julLevel = slf4jLevelIntToJULLevel(level);
625 // the logger.isLoggable check avoids the unconditional
626 // construction of location data for disabled log
627 // statements. As of 2008-07-31, callers of this method
628 // do not perform this check. See also
629 // http://jira.qos.ch/browse/SLF4J-81
630 if (logger.isLoggable(julLevel)) {
631 log(callerFQCN, julLevel, message, t);
632 }
633 }
634
635 private Level slf4jLevelIntToJULLevel(int slf4jLevelInt) {
623636 Level julLevel;
624 switch (level) {
637 switch (slf4jLevelInt) {
625638 case LocationAwareLogger.TRACE_INT:
626639 julLevel = Level.FINEST;
627640 break;
638651 julLevel = Level.SEVERE;
639652 break;
640653 default:
641 throw new IllegalStateException("Level number " + level + " is not recognized.");
642 }
643 // the logger.isLoggable check avoids the unconditional
644 // construction of location data for disabled log
645 // statements. As of 2008-07-31, callers of this method
646 // do not perform this check. See also
647 // http://jira.qos.ch/browse/SLF4J-81
654 throw new IllegalStateException("Level number " + slf4jLevelInt + " is not recognized.");
655 }
656 return julLevel;
657 }
658
659 /**
660 * @since 1.7.15
661 */
662 public void log(LoggingEvent event) {
663 Level julLevel = slf4jLevelIntToJULLevel(event.getLevel().toInt());
648664 if (logger.isLoggable(julLevel)) {
649 log(callerFQCN, julLevel, message, t);
650 }
665 LogRecord record = eventToRecord(event, julLevel);
666 logger.log(record);
667 }
668 }
669
670 private LogRecord eventToRecord(LoggingEvent event, Level julLevel) {
671 String format = event.getMessage();
672 Object[] arguments = event.getArgumentArray();
673 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
674 if (ft.getThrowable() != null && event.getThrowable() != null) {
675 throw new IllegalArgumentException("both last element in argument array and last argument are of type Throwable");
676 }
677
678 Throwable t = event.getThrowable();
679 if (ft.getThrowable() != null) {
680 t = ft.getThrowable();
681 throw new IllegalStateException("fix above code");
682 }
683
684 LogRecord record = new LogRecord(julLevel, ft.getMessage());
685 record.setLoggerName(event.getLoggerName());
686 record.setMillis(event.getTimeStamp());
687 record.setSourceClassName(EventConstants.NA_SUBST);
688 record.setSourceMethodName(EventConstants.NA_SUBST);
689
690 record.setThrown(t);
691 return record;
651692 }
652693 }
4242
4343 public JDK14LoggerFactory() {
4444 loggerMap = new ConcurrentHashMap<String, Logger>();
45 // ensure jul initialization. see also SLF4J-359
46 java.util.logging.LogManager.getLogManager();
4547 }
4648
4749 /*
4040
4141 private StaticMDCBinder() {
4242 }
43
43
4444 /**
4545 * Return the singleton of this class.
4646 *
5050 public static final StaticMDCBinder getSingleton() {
5151 return SINGLETON;
5252 }
53
53
5454 /**
5555 * Currently this method always returns an instance of
5656 * {@link BasicMDCAdapter}.
5656 public static StaticMarkerBinder getSingleton() {
5757 return SINGLETON;
5858 }
59
59
6060 /**
6161 * Currently this method always returns an instance of
6262 * {@link BasicMarkerFactory}.
44 Bundle-Vendor: SLF4J.ORG
55 Bundle-RequiredExecutionEnvironment: J2SE-1.5
66 Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}, org.slf4j.helpers;version=${parsedVersion.osgiVersion}
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
8 org.slf4j.spi;version=${parsedVersion.osgiVersion},
9 org.slf4j.helpers;version=${parsedVersion.osgiVersion},
10 org.slf4j.event;version=${parsedVersion.osgiVersion}
811 Fragment-Host: slf4j.api
0 package org.slf4j;
1
2 public class LoggerFactoryFriend {
3 static public void reset() {
4 LoggerFactory.reset();
5 }
6 }
2525
2626 import static org.junit.Assert.assertNotNull;
2727
28 import java.util.Random;
2829 import java.util.logging.Handler;
2930 import java.util.logging.LogRecord;
3031 import java.util.logging.Logger;
3536
3637 public class JDK14AdapterLoggerNameTest {
3738 private MockHandler mockHandler;
38
39 static Random random = new Random(System.currentTimeMillis());
40 long diff = random.nextInt(10000);
41 String loggerName = "JDK14AdapterLoggerNameTest"+diff;
42
43 Logger logger = Logger.getLogger(loggerName);
44
3945 @Before
4046 public void setUp() throws Exception {
41 Logger logger = Logger.getLogger("TEST");
42 mockHandler = new MockHandler();
43 removeHandlers(logger);
44 logger.addHandler(mockHandler);
47 Logger logger = Logger.getLogger(loggerName);
48 addMockHandler(logger);
4549 }
50
51
4652
4753 @After
4854 public void tearDown() throws Exception {
49 removeHandlers(Logger.getLogger("TEST"));
55 removeHandlers(Logger.getLogger(loggerName));
5056 }
5157
5258 @Test
53 public void testLoggerNameusingJdkLogging() throws Exception {
54 Logger.getLogger("TEST").info("test message");
59 public void testLoggerNameUsingJdkLogging() throws Exception {
60 logger.info("test message");
5561 assertCorrectLoggerName();
56
5762 }
5863
5964 @Test
6065 public void testLoggerNameUsingSlf4j() throws Exception {
6166 JDK14LoggerFactory factory = new JDK14LoggerFactory();
62 org.slf4j.Logger logger = factory.getLogger("TEST");
67 org.slf4j.Logger logger = factory.getLogger(loggerName);
6368 logger.info("test message");
6469 assertCorrectLoggerName();
6570 }
6671
72 private void addMockHandler(Logger logger) {
73 mockHandler = new MockHandler();
74 removeHandlers(logger);
75 logger.addHandler(mockHandler);
76 }
77
6778 private void removeHandlers(Logger logger) {
6879 logger.setUseParentHandlers(false);
6980 Handler[] handlers = logger.getHandlers();
0 /**
1 * Copyright (c) 2004-2016 QOS.ch
2 * All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 package org.slf4j.impl;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.fail;
28
29 import java.util.List;
30 import java.util.Random;
31 import java.util.concurrent.BrokenBarrierException;
32 import java.util.concurrent.CyclicBarrier;
33 import java.util.concurrent.atomic.AtomicLong;
34 import java.util.logging.Handler;
35 import java.util.logging.LogRecord;
36
37 import org.junit.After;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 public class MultithreadedInitializationTest {
44
45 final static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2;
46
47 private static AtomicLong EVENT_COUNT = new AtomicLong(0);
48
49 final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
50
51 int diff = new Random().nextInt(10000);
52 String packagePrefix = "org.slf4j.impl.MultithreadedInitializationTest" + diff;
53
54 java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(packagePrefix);
55
56 @Before
57 public void addRecordingHandler() {
58 julLogger.addHandler(new RecordingHandler());
59 }
60
61 @After
62 public void tearDown() throws Exception {
63 Handler[] handlers = julLogger.getHandlers();
64 for (int i = 0; i < handlers.length; i++) {
65 if (handlers[i] instanceof RecordingHandler) {
66 julLogger.removeHandler(handlers[i]);
67 }
68 }
69 }
70
71 @Test
72 public void multiThreadedInitialization() throws InterruptedException, BrokenBarrierException {
73 System.out.println("THREAD_COUNT=" + THREAD_COUNT);
74 LoggerAccessingThread[] accessors = harness();
75
76 for (int i = 0; i < accessors.length; i++) {
77 LoggerAccessingThread accessor = accessors[i];
78 EVENT_COUNT.getAndIncrement();
79 if (accessor.logger == null) {
80 fail("logger for LoggerAccessingThread " + i + " is not set");
81 }
82 accessor.logger.info("post harness");
83 }
84
85 Logger logger = LoggerFactory.getLogger(packagePrefix + ".test");
86 logger.info("hello");
87 EVENT_COUNT.getAndIncrement();
88
89 List<LogRecord> records = getRecordedEvents();
90 assertEquals(EVENT_COUNT.get(), records.size());
91 }
92
93 private List<LogRecord> getRecordedEvents() {
94 RecordingHandler ra = findRecordingHandler();
95 if (ra == null) {
96 fail("failed to fing RecordingHandler");
97 }
98 return ra.records;
99 }
100
101 private RecordingHandler findRecordingHandler() {
102 Handler[] handlers = julLogger.getHandlers();
103 for (Handler h : handlers) {
104 if (h instanceof RecordingHandler)
105 return (RecordingHandler) h;
106 }
107 return null;
108 }
109
110 private LoggerAccessingThread[] harness() throws InterruptedException, BrokenBarrierException {
111 LoggerAccessingThread[] threads = new LoggerAccessingThread[THREAD_COUNT];
112 final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
113 for (int i = 0; i < THREAD_COUNT; i++) {
114 threads[i] = new LoggerAccessingThread(barrier, i);
115 threads[i].start();
116 }
117
118 // trigger barrier
119 barrier.await();
120
121 for (int i = 0; i < THREAD_COUNT; i++) {
122 threads[i].join();
123 }
124
125 return threads;
126 }
127
128 class LoggerAccessingThread extends Thread {
129 final CyclicBarrier barrier;
130 volatile Logger logger;
131 final int count;
132
133 LoggerAccessingThread(CyclicBarrier barrier, int count) {
134 this.barrier = barrier;
135 this.count = count;
136 }
137
138 public void run() {
139 try {
140 barrier.await();
141 } catch (Exception e) {
142 e.printStackTrace();
143 }
144 for (int i = 0; i < 64; i++) {
145 logger = LoggerFactory.getLogger(packagePrefix + ".LoggerAccessingThread" + count + "-" + i);
146 logger.info("in run method");
147 EVENT_COUNT.getAndIncrement();
148 }
149 }
150 };
151
152 }
2323 */
2424 package org.slf4j.impl;
2525
26 import org.junit.Ignore;
2627 import org.junit.Test;
2728 import org.slf4j.Logger;
2829 import org.slf4j.LoggerFactory;
2930 import org.slf4j.helpers.BogoPerf;
3031
32 @Ignore
3133 public class PerfTest {
3234
3335 static long REFERENCE_BIPS = 9000;
3436
3537 @Test
36 public void testBug72() {
38 public void issue63() {
3739
3840 int LEN = 1000 * 1000 * 10;
3941 debugLoop(LEN); // warm up
0 package org.slf4j.impl;
1
2 import java.util.ArrayList;
3 import java.util.Collections;
4 import java.util.List;
5 import java.util.logging.Handler;
6 import java.util.logging.LogRecord;
7
8 public class RecordingHandler extends Handler {
9
10 List<LogRecord> records = Collections.synchronizedList(new ArrayList<LogRecord>());
11
12 @Override
13 public void publish(LogRecord record) {
14 records.add(record);
15 }
16
17 @Override
18 public void flush() {
19 }
20
21 @Override
22 public void close() throws SecurityException {
23 }
24
25 }
4141 * See http://jira.qos.ch/browse/SLF4J-252
4242 * @author Thorbjorn Ravn Andersen
4343 */
44 public class LoggerSerializationTest {
44 public class LoggerSerializationTest {
4545
4646 static class LoggerHolder implements Serializable {
4747 private static final long serialVersionUID = 1L;
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-log4j12</artifactId>
2323 */
2424 package org.slf4j.impl;
2525
26 import static org.slf4j.event.EventConstants.NA_SUBST;
27
2628 import java.io.Serializable;
2729
2830 import org.apache.log4j.Level;
31 import org.apache.log4j.spi.LocationInfo;
32 import org.apache.log4j.spi.ThrowableInformation;
2933 import org.slf4j.Logger;
3034 import org.slf4j.Marker;
35 import org.slf4j.event.LoggingEvent;
3136 import org.slf4j.helpers.FormattingTuple;
3237 import org.slf4j.helpers.MarkerIgnoringBase;
3338 import org.slf4j.helpers.MessageFormatter;
571576 }
572577
573578 public void log(Marker marker, String callerFQCN, int level, String msg, Object[] argArray, Throwable t) {
579 Level log4jLevel = toLog4jLevel(level);
580 logger.log(callerFQCN, log4jLevel, msg, t);
581 }
582
583 private Level toLog4jLevel(int level) {
574584 Level log4jLevel;
575585 switch (level) {
576586 case LocationAwareLogger.TRACE_INT:
591601 default:
592602 throw new IllegalStateException("Level number " + level + " is not recognized.");
593603 }
594 logger.log(callerFQCN, log4jLevel, msg, t);
604 return log4jLevel;
605 }
606
607 public void log(LoggingEvent event) {
608 Level log4jLevel = toLog4jLevel(event.getLevel().toInt());
609 if (!logger.isEnabledFor(log4jLevel))
610 return;
611
612 org.apache.log4j.spi.LoggingEvent log4jevent = toLog4jEvent(event, log4jLevel);
613 logger.callAppenders(log4jevent);
614
615 }
616
617 private org.apache.log4j.spi.LoggingEvent toLog4jEvent(LoggingEvent event, Level log4jLevel) {
618
619 FormattingTuple ft = MessageFormatter.format(event.getMessage(), event.getArgumentArray(), event.getThrowable());
620
621 LocationInfo locationInfo = new LocationInfo(NA_SUBST, NA_SUBST, NA_SUBST, "0");
622
623 ThrowableInformation ti = null;
624 Throwable t = ft.getThrowable();
625 if (t != null)
626 ti = new ThrowableInformation(t);
627
628 org.apache.log4j.spi.LoggingEvent log4jEvent = new org.apache.log4j.spi.LoggingEvent(FQCN, logger, event.getTimeStamp(), log4jLevel, ft.getMessage(),
629 event.getThreadName(), ti, null, locationInfo, null);
630
631 return log4jEvent;
595632 }
596633
597634 }
4040 public class Log4jLoggerFactory implements ILoggerFactory {
4141
4242 private static final String LOG4J_DELEGATION_LOOP_URL = "http://www.slf4j.org/codes.html#log4jDelegationLoop";
43
43
4444 // check for delegation loops
4545 static {
4646 try {
6161
6262 public Log4jLoggerFactory() {
6363 loggerMap = new ConcurrentHashMap<String, Logger>();
64 // force log4j to initialize
65 org.apache.log4j.LogManager.getRootLogger();
6466 }
6567
6668 /*
3939
4040 private StaticMDCBinder() {
4141 }
42
42
4343 /**
4444 * Return the singleton of this class.
4545 *
4949 public static final StaticMDCBinder getSingleton() {
5050 return SINGLETON;
5151 }
52
52
5353 /**
5454 * Currently this method always returns an instance of
5555 * {@link StaticMDCBinder}.
5656 public static StaticMarkerBinder getSingleton() {
5757 return SINGLETON;
5858 }
59
59
6060 /**
6161 * Currently this method always returns an instance of
6262 * {@link BasicMarkerFactory}.
44 Bundle-Vendor: SLF4J.ORG
55 Bundle-RequiredExecutionEnvironment: J2SE-1.5
66 Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}, org.slf4j.helpers;version=${parsedVersion.osgiVersion}, org.apache.log4j
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
8 org.slf4j.spi;version=${parsedVersion.osgiVersion},
9 org.slf4j.helpers;version=${parsedVersion.osgiVersion},
10 org.slf4j.event;version=${parsedVersion.osgiVersion},
11 org.apache.log4j
812 Fragment-Host: slf4j.api
4747 ListAppender listAppender = new ListAppender();
4848 org.apache.log4j.Logger root;
4949
50
5150 @Before
5251 public void setUp() throws Exception {
5352 root = org.apache.log4j.Logger.getRootLogger();
5857 public void tearDown() throws Exception {
5958 root.getLoggerRepository().resetConfiguration();
6059 }
61
60
6261 @Test
6362 public void test1() {
6463 Logger logger = LoggerFactory.getLogger("test1");
118117 String[] parameters = null;
119118 String msg = "hello {}";
120119
121 logger.debug(msg, (Object[]) parameters);
122
120 logger.debug(msg, (Object[]) parameters);
121
123122 assertEquals(1, listAppender.list.size());
124123 LoggingEvent e = (LoggingEvent) listAppender.list.get(0);
125124 assertEquals(msg, e.getMessage());
0 /**
1 * Copyright (c) 2004-2011 QOS.ch
2 * All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 package org.slf4j.impl;
25
26 import static org.junit.Assert.assertEquals;
27
28 import java.util.List;
29 import java.util.Random;
30 import java.util.concurrent.BrokenBarrierException;
31 import java.util.concurrent.CyclicBarrier;
32 import java.util.concurrent.atomic.AtomicLong;
33
34 import org.apache.log4j.LogManager;
35 import org.apache.log4j.spi.LoggingEvent;
36 import org.junit.After;
37 import org.junit.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class MultithreadedInitializationTest {
42
43 // value of LogManager.DEFAULT_CONFIGURATION_KEY;
44 static String CONFIG_FILE_KEY = "log4j.configuration";
45
46 final static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2;
47
48 private static AtomicLong EVENT_COUNT = new AtomicLong(0);
49
50 final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
51
52 int diff = new Random().nextInt(10000);
53 String loggerName = "org.slf4j.impl.RecursiveInitializationTest";
54
55 @After
56 public void tearDown() throws Exception {
57 System.clearProperty(CONFIG_FILE_KEY);
58 }
59
60 @Test
61 public void multiThreadedInitialization() throws InterruptedException, BrokenBarrierException {
62 System.out.println("THREAD_COUNT=" + THREAD_COUNT);
63 System.setProperty(CONFIG_FILE_KEY, "recursiveInitWithActivationDelay.properties");
64 LoggerAccessingThread[] accessors = harness();
65
66 for (LoggerAccessingThread accessor : accessors) {
67 EVENT_COUNT.getAndIncrement();
68 accessor.logger.info("post harness");
69 }
70
71 Logger logger = LoggerFactory.getLogger(loggerName + ".slowInitialization-" + diff);
72 logger.info("hello");
73 EVENT_COUNT.getAndIncrement();
74
75 List<LoggingEvent> events = getRecordedEvents();
76 // 3 evetns generated by RecursiveAppender
77 assertEquals(EVENT_COUNT.get() + 3, events.size());
78 }
79
80 private List<LoggingEvent> getRecordedEvents() {
81 org.apache.log4j.Logger root = LogManager.getRootLogger();
82
83 RecursiveAppender ra = (RecursiveAppender) root.getAppender("RECURSIVE");
84 return ra.events;
85 }
86
87 private static LoggerAccessingThread[] harness() throws InterruptedException, BrokenBarrierException {
88 LoggerAccessingThread[] threads = new LoggerAccessingThread[THREAD_COUNT];
89 final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
90 for (int i = 0; i < THREAD_COUNT; i++) {
91 threads[i] = new LoggerAccessingThread(barrier, i);
92 threads[i].start();
93 }
94
95 barrier.await();
96 for (int i = 0; i < THREAD_COUNT; i++) {
97 threads[i].join();
98 }
99 return threads;
100 }
101
102 static class LoggerAccessingThread extends Thread {
103 final CyclicBarrier barrier;
104 Logger logger;
105 int count;
106
107 LoggerAccessingThread(CyclicBarrier barrier, int count) {
108 this.barrier = barrier;
109 this.count = count;
110 }
111
112 public void run() {
113 try {
114 barrier.await();
115 } catch (Exception e) {
116 e.printStackTrace();
117 }
118 for (int i = 0; i < 64; i++) {
119 logger = LoggerFactory.getLogger(this.getClass().getName() + "-" + count + "-" + i);
120 logger.info("in run method");
121 EVENT_COUNT.getAndIncrement();
122 }
123 }
124 };
125
126 }
2323 */
2424 package org.slf4j.impl;
2525
26 import java.util.ArrayList;
27 import java.util.List;
2628 import java.util.Random;
2729
2830 import org.apache.log4j.AppenderSkeleton;
3335 public class RecursiveAppender extends AppenderSkeleton {
3436
3537 int diff = new Random().nextInt();
38 int activationDelay = 0;
39 String loggerName = "org.slf4j.impl.RecursiveAppender" + diff;
40
41 List<LoggingEvent> events = new ArrayList<LoggingEvent>();
3642
3743 public RecursiveAppender() {
38 System.out.println("in RecursiveAppender constructor");
39 Logger logger = LoggerFactory.getLogger("RecursiveAppender" + diff);
40 System.out.println("logger class=" + logger.getClass().getName());
44 System.out.println("entering RecursiveAppender constructor");
45 Logger logger = LoggerFactory.getLogger(loggerName);
4146 logger.info("Calling a logger in the constructor");
47 System.out.println("exiting RecursiveAppender constructor");
4248 }
4349
44 protected void append(LoggingEvent arg0) {
50 protected void append(LoggingEvent e) {
51 events.add(e);
4552 }
4653
4754 public void close() {
5057 public boolean requiresLayout() {
5158 return false;
5259 }
60
61 @Override
62 public void activateOptions() {
63 System.out.println("entering RecursiveAppender.activateOptions");
64 if (activationDelay > 0) {
65 Logger logger = LoggerFactory.getLogger(loggerName);
66 logger.info("About to wait {} millis", activationDelay);
67 try {
68 Thread.sleep(activationDelay);
69 } catch (InterruptedException e) {
70 e.printStackTrace();
71 }
72 logger.info("Done waiting {} millis", activationDelay);
73 }
74 super.activateOptions();
75
76 System.out.println("exiting RecursiveAppender.activateOptions");
77 }
78
79 public int getActivationDelay() {
80 return activationDelay;
81 }
82
83 public void setActivationDelay(int activationDelay) {
84 this.activationDelay = activationDelay;
85 }
86
5387 }
2626 import java.util.Random;
2727
2828 import org.junit.After;
29 import org.junit.Before;
3029 import org.junit.Test;
3130 import org.slf4j.Logger;
3231 import org.slf4j.LoggerFactory;
32
3333 public class RecursiveInitializationTest {
3434
3535 // value of LogManager.DEFAULT_CONFIGURATION_KEY;
3636 static String CONFIG_FILE_KEY = "log4j.configuration";
3737
3838 int diff = new Random().nextInt(10000);
39
40 @Before
41 public void setUp() throws Exception {
42 System.setProperty(CONFIG_FILE_KEY, "recursiveInit.properties");
43 }
39 String loggerName = "org.slf4j.impl.RecursiveInitializationTest";
4440
4541 @After
4642 public void tearDown() throws Exception {
4844 }
4945
5046 @Test
51 public void testLog4j() {
52 Logger logger = LoggerFactory.getLogger("x" + diff);
53 System.out.println("logger class=" + logger.getClass().getName());
47 public void loggingDuringInitialization() {
48 System.setProperty(CONFIG_FILE_KEY, "recursiveInit.properties");
49 Logger logger = LoggerFactory.getLogger(loggerName + ".loggingDuringInitialization-" + diff);
5450 logger.info("hello");
5551 }
5652
0 log4j.debug=true
1 log4j.rootLogger=DEBUG, CONSOLE, RECURSIVE
2
3 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
4 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
5 log4j.appender.CONSOLE.layout.ConversionPattern=CON %d [%t] %c - %m%n
6
7 log4j.appender.RECURSIVE=org.slf4j.impl.RecursiveAppender
8 log4j.appender.RECURSIVE.activationDelay=10
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-migrator</artifactId>
4545 import org.slf4j.migrator.Constant;
4646 import org.slf4j.migrator.helper.SpringLayoutHelper;
4747
48 /**
49 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
50 * Builder, which is free for non-commercial use. If Jigloo is being used
51 * commercially (ie, by a corporation, company or business for any purpose
52 * whatever) then you should purchase a license for each developer using Jigloo.
53 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
54 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
55 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
56 * ANY CORPORATE OR COMMERCIAL PURPOSE.
57 */
5848 public class MigratorFrame extends JFrame implements ActionListener {
5949 private static final long serialVersionUID = 1L;
6050
3030 import org.junit.Test;
3131 import org.slf4j.migrator.internal.NopProgressListener;
3232 import org.slf4j.migrator.line.EmptyRuleSet;
33 public class FileConverterTest {
3433
34 public class FileConverterTest {
3535
3636 @Test
3737 @Ignore
2929 import org.junit.Test;
3030 import org.slf4j.migrator.internal.NopProgressListener;
3131
32 public class ProjectConverterTest {
32 public class ProjectConverterTest {
3333
3434 public void test() {
3535 }
2727 import static org.junit.Assert.assertTrue;
2828
2929 import org.junit.Test;
30
3031 public class AbbreviatorTest {
3132
3233 static final char FS = '/';
2626 import static org.junit.Assert.assertEquals;
2727
2828 import org.junit.Test;
29
2930 public class JCLRuleSetTest {
3031
3132 LineConverter jclConverter = new LineConverter(new JCLRuleSet());
3738 // Log import replacement
3839 assertEquals("import org.slf4j.Logger;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.Log;"));
3940 }
40
4141
4242 @Test
4343 public void testLogFactoryGetLogReplacement() {
9292 jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
9393 }
9494
95
9695 @Test
9796 public void testLogDeclarationReplacement() {
9897
2626 import static org.junit.Assert.assertEquals;
2727
2828 import org.junit.Test;
29 public class NoConversionTest {
29
30 public class NoConversionTest {
3031
3132 /**
3233 * This test shows that performing JCL to SLF4J conversion has no impact on
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.14</version>
9 <version>1.7.19</version>
1010 </parent>
1111
1212 <artifactId>slf4j-nop</artifactId>
5050 public static final StaticMDCBinder getSingleton() {
5151 return SINGLETON;
5252 }
53
53
5454 /**
5555 * Currently this method always returns an instance of
5656 * {@link StaticMDCBinder}.
5656 public static StaticMarkerBinder getSingleton() {
5757 return SINGLETON;
5858 }
59
59
6060 /**
6161 * Currently this method always returns an instance of
6262 * {@link BasicMarkerFactory}.
44 Bundle-Vendor: SLF4J.ORG
55 Bundle-RequiredExecutionEnvironment: J2SE-1.5
66 Export-Package: org.slf4j.impl;version=${parsedVersion.osgiVersion}
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion}, org.slf4j.spi;version=${parsedVersion.osgiVersion}, org.slf4j.helpers;version=${parsedVersion.osgiVersion}
7 Import-Package: org.slf4j;version=${parsedVersion.osgiVersion},
8 org.slf4j.spi;version=${parsedVersion.osgiVersion},
9 org.slf4j.helpers;version=${parsedVersion.osgiVersion},
10 org.slf4j.event;version=${parsedVersion.osgiVersion}
811 Fragment-Host: slf4j.api
0 package org.slf4j;
1
2 public class LoggerFactoryFriend {
3 static public void reset() {
4 LoggerFactory.reset();
5 }
6 }
0 /**
1 * Copyright (c) 2004-2016 QOS.ch
2 * All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23