Imported Upstream version 1.7.13
Emmanuel Bourg
8 years ago
12 | 12 | <echo message="runtime classpath: ${runtime_classpath}" /> |
13 | 13 | <echo message="test classpath: ${test_classpath}" /> |
14 | 14 | <echo message="plugin classpath: ${plugin_classpath}" /> |
15 | <echo message="basedir: ${basedir}" /> | |
16 | ||
17 | ||
18 | <!--<property name="path_to_policy" value="file:./integration/src/policy/java-under-ant.policy"/>--> | |
15 | 19 | |
16 | 20 | |
17 | 21 | <path id="path142Binding"> |
102 | 106 | testMatch, |
103 | 107 | testMultiBinding, |
104 | 108 | testIncompatibleMultiBinding, |
105 | testFuture_16Series"> | |
109 | testFuture_16Series, | |
110 | testActiveSecurityManager"> | |
106 | 111 | </target> |
107 | 112 | |
108 | 113 | |
196 | 201 | </junit> |
197 | 202 | |
198 | 203 | </target> |
204 | ||
205 | ||
206 | <condition property="runFromWithinIntegrationModule"> | |
207 | <contains string="${user.dir}" substring="integration" /> | |
208 | </condition> | |
209 | ||
210 | <target name="setPathToPolicy_FromTop" unless="runFromWithinIntegrationModule"> | |
211 | <echo>setPathToPolicy_FromTop</echo> | |
212 | <property name="path_to_policy" value="file:./integration/src/policy/java-under-ant.policy"/> | |
213 | </target> | |
214 | ||
215 | <target name="setPathToPolicy_FromIntegration" if="runFromWithinIntegrationModule"> | |
216 | <echo>setPathToPolicy_FromInegration </echo> | |
217 | <property name="path_to_policy" value="file:./src/policy/java-under-ant.policy"/> | |
218 | </target> | |
219 | ||
220 | ||
221 | <target name="testActiveSecurityManager" depends="setPathToPolicy_FromTop, setPathToPolicy_FromIntegration"> | |
222 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
223 | <jvmarg value="-Djava.security.manager"/> | |
224 | <jvmarg value="-Djava.security.policy=${path_to_policy}"/> | |
225 | <jvmarg value="-Dslf4j.detectLoggerNameMismatch=true"/> | |
226 | <classpath refid="pathCurrent" /> | |
227 | <formatter type="plain" /> | |
228 | <test fork="yes" todir="target/unit-reports" | |
229 | outfile="TEST-SecurityManager" | |
230 | name="org.slf4j.issues.Issue324Test" /> | |
231 | </junit> | |
232 | </target> | |
233 | ||
199 | 234 | </project>⏎ |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | ||
13 | 11 | |
14 | 12 | <artifactId>integration</artifactId> |
15 | 13 | <packaging>jar</packaging> |
36 | 34 | <artifactId>ant-junit</artifactId> |
37 | 35 | <version>1.6.5</version> |
38 | 36 | </dependency> |
39 | ||
40 | 37 | |
41 | 38 | <!-- some test run Felix in hosted mode --> |
42 | 39 | <dependency> |
0 | ||
1 | grant { | |
2 | ||
3 | // note that java.lang.RuntimePermission createSecurityManager is NOT granted | |
4 | ||
5 | permission java.util.PropertyPermission "user.dir", "read"; | |
6 | permission java.util.PropertyPermission "*", "read"; | |
7 | ||
8 | permission java.net.SocketPermission "*", "connect,resolve"; | |
9 | };⏎ |
0 | ||
1 | grant { | |
2 | ||
3 | // note that java.lang.RuntimePermission createSecurityManager is NOT granted | |
4 | ||
5 | permission java.util.PropertyPermission "user.dir", "read"; | |
6 | ||
7 | // permissions required for Ant's Junit runner | |
8 | permission java.util.PropertyPermission "*", "read, write"; | |
9 | permission java.io.FilePermission "./-", "read"; | |
10 | permission java.io.FilePermission "./-", "write"; | |
11 | permission java.lang.RuntimePermission "setIO"; | |
12 | };⏎ |
0 | package org.slf4j.issues; | |
1 | ||
2 | import org.slf4j.Logger; | |
3 | import org.slf4j.LoggerFactory; | |
4 | ||
5 | import junit.framework.TestCase; | |
6 | ||
7 | public class Issue324Test extends TestCase { | |
8 | ||
9 | ||
10 | public void testLoggerCreationInPresenseOfSecurityManager() { | |
11 | String currentDir = System.getProperty("user.dir"); | |
12 | System.out.println("currentDir:"+currentDir); | |
13 | Logger logger = LoggerFactory.getLogger(Issue324Test.class); | |
14 | logger.debug("hello"); | |
15 | } | |
16 | } |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
0 | 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
1 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
2 | 3 | |
3 | 4 | <parent> |
4 | 5 | <groupId>org.slf4j</groupId> |
5 | 6 | <artifactId>slf4j-parent</artifactId> |
6 | <version>1.7.12</version> | |
7 | <version>1.7.13</version> | |
7 | 8 | </parent> |
8 | 9 | |
9 | 10 | <modelVersion>4.0.0</modelVersion> |
14 | 15 | <description>JCL 1.1.1 implemented over SLF4J</description> |
15 | 16 | <url>http://www.slf4j.org</url> |
16 | 17 | |
17 | ||
18 | 18 | <dependencies> |
19 | <!-- | |
20 | <dependency> | |
21 | <groupId>org.slf4j</groupId> | |
22 | <artifactId>slf4j-nop</artifactId> | |
23 | <version>${project.version}</version> | |
24 | <scope>provided</scope> | |
25 | </dependency> | |
26 | --> | |
27 | ||
28 | 19 | <dependency> |
29 | 20 | <groupId>org.slf4j</groupId> |
30 | 21 | <artifactId>slf4j-api</artifactId> |
31 | 22 | </dependency> |
32 | ||
33 | 23 | <dependency> |
34 | 24 | <groupId>org.slf4j</groupId> |
35 | 25 | <artifactId>slf4j-jdk14</artifactId> |
36 | 26 | <scope>test</scope> |
37 | 27 | </dependency> |
38 | ||
39 | 28 | </dependencies> |
40 | 29 | |
41 | <build> | |
42 | <plugins> | |
43 | ||
44 | <plugin> | |
45 | <groupId>org.apache.maven.plugins</groupId> | |
46 | <artifactId>maven-jar-plugin</artifactId> | |
47 | <configuration> | |
48 | <archive> | |
49 | <manifestEntries> | |
50 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
51 | <Bundle-Description>${project.description}</Bundle-Description> | |
52 | <Implementation-Version>${project.version}</Implementation-Version> | |
53 | </manifestEntries> | |
54 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
55 | </archive> | |
56 | </configuration> | |
57 | </plugin> | |
58 | ||
59 | </plugins> | |
60 | ||
61 | ||
62 | </build> | |
63 | ||
64 | 30 | </project>⏎ |
24 | 24 | |
25 | 25 | package org.apache.commons.logging; |
26 | 26 | |
27 | import junit.framework.TestCase; | |
27 | import static org.junit.Assert.assertFalse; | |
28 | import static org.junit.Assert.assertTrue; | |
28 | 29 | |
29 | public class InvokeJCLTest extends TestCase { | |
30 | import org.junit.Test; | |
30 | 31 | |
32 | public class InvokeJCLTest { | |
33 | ||
34 | @Test | |
31 | 35 | public void testIsEnabledAPI() { |
32 | 36 | // assume that we are running over slf4j-jdk14 |
33 | 37 | Log log = LogFactory.getLog(InvokeJCLTest.class); |
39 | 43 | assertTrue(log.isFatalEnabled()); |
40 | 44 | } |
41 | 45 | |
46 | @Test | |
42 | 47 | public void testPrintAPI() { |
43 | 48 | Log log = LogFactory.getLog(InvokeJCLTest.class); |
44 | 49 | Exception e = new Exception("just testing"); |
+12
-12
29 | 29 | import java.io.ObjectInputStream; |
30 | 30 | import java.io.ObjectOutputStream; |
31 | 31 | |
32 | import junit.framework.TestCase; | |
33 | ||
34 | 32 | import org.apache.commons.logging.Log; |
35 | 33 | import org.apache.commons.logging.LogFactory; |
34 | import org.junit.After; | |
35 | import org.junit.Before; | |
36 | import org.junit.Test; | |
36 | 37 | import org.slf4j.impl.JDK14LoggerFactory; |
37 | 38 | import org.slf4j.spi.LocationAwareLogger; |
38 | 39 | |
39 | public class SerializationTest extends TestCase { | |
40 | public class SerializationTest { | |
40 | 41 | |
41 | 42 | ObjectInputStream ois; |
42 | 43 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
43 | 44 | ObjectOutputStream oos; |
44 | 45 | |
45 | public SerializationTest(String name) { | |
46 | super(name); | |
46 | @Before | |
47 | public void setUp() throws Exception { | |
48 | oos = new ObjectOutputStream(baos); | |
47 | 49 | } |
48 | 50 | |
49 | protected void setUp() throws Exception { | |
50 | oos = new ObjectOutputStream(baos); | |
51 | super.setUp(); | |
52 | } | |
53 | ||
54 | protected void tearDown() throws Exception { | |
55 | super.tearDown(); | |
51 | @After | |
52 | public void tearDown() throws Exception { | |
56 | 53 | oos.close(); |
57 | 54 | } |
58 | 55 | |
66 | 63 | resuscitatedLog.isDebugEnabled(); |
67 | 64 | } |
68 | 65 | |
66 | @Test | |
69 | 67 | public void testSLF4JLog() throws Exception { |
70 | 68 | JDK14LoggerFactory factory = new JDK14LoggerFactory(); |
71 | 69 | SLF4JLog log = new SLF4JLog(factory.getLogger("x")); |
73 | 71 | verify(); |
74 | 72 | } |
75 | 73 | |
74 | @Test | |
76 | 75 | public void testSmoke() throws Exception { |
77 | 76 | Log log = LogFactory.getLog("testing"); |
78 | 77 | oos.writeObject(log); |
79 | 78 | verify(); |
80 | 79 | } |
81 | 80 | |
81 | @Test | |
82 | 82 | public void testLocationAware() throws Exception { |
83 | 83 | JDK14LoggerFactory factory = new JDK14LoggerFactory(); |
84 | 84 | SLF4JLocationAwareLog log = new SLF4JLocationAwareLog((LocationAwareLogger) factory.getLogger("x")); |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | 11 | |
13 | 12 | <artifactId>jul-to-slf4j</artifactId> |
31 | 30 | </dependency> |
32 | 31 | </dependencies> |
33 | 32 | |
34 | <build> | |
35 | <plugins> | |
36 | <plugin> | |
37 | <groupId>org.apache.maven.plugins</groupId> | |
38 | <artifactId>maven-compiler-plugin</artifactId> | |
39 | <configuration> | |
40 | <source>${required.jdk.version}</source> | |
41 | <target>${required.jdk.version}</target> | |
42 | </configuration> | |
43 | </plugin> | |
44 | <plugin> | |
45 | <groupId>org.apache.maven.plugins</groupId> | |
46 | <artifactId>maven-jar-plugin</artifactId> | |
47 | <configuration> | |
48 | <archive> | |
49 | <manifestEntries> | |
50 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
51 | <Bundle-Description>${project.description}</Bundle-Description> | |
52 | <Implementation-Version>${project.version} | |
53 | </Implementation-Version> | |
54 | </manifestEntries> | |
55 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
56 | </archive> | |
57 | </configuration> | |
58 | </plugin> | |
59 | ||
60 | </plugins> | |
61 | </build> | |
62 | ||
63 | 33 | </project>⏎ |
35 | 35 | import org.slf4j.LoggerFactory; |
36 | 36 | import org.slf4j.spi.LocationAwareLogger; |
37 | 37 | |
38 | // Based on http://bugzilla.slf4j.org/show_bug.cgi?id=38 | |
38 | // Based on http://jira.qos.ch/browse/SLF4J-30 | |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * <p>Bridge/route all JUL log records to the SLF4J API.</p> |
258 | 258 | } |
259 | 259 | Object[] params = record.getParameters(); |
260 | 260 | // avoid formatting when there are no or 0 parameters. see also |
261 | // http://bugzilla.slf4j.org/show_bug.cgi?id=212 | |
261 | // http://jira.qos.ch/browse/SLF4J-203 | |
262 | 262 | if (params != null && params.length > 0) { |
263 | message = MessageFormat.format(message, params); | |
263 | try { | |
264 | message = MessageFormat.format(message, params); | |
265 | } catch (IllegalArgumentException e) { | |
266 | // default to the same behavior as in java.util.logging.Formatter.formatMessage(LogRecord) | |
267 | // see also http://jira.qos.ch/browse/SLF4J-337 | |
268 | return message; | |
269 | } | |
264 | 270 | } |
265 | 271 | return message; |
266 | 272 | } |
288 | 294 | // this is a check to avoid calling the underlying logging system |
289 | 295 | // with a null message. While it is legitimate to invoke j.u.l. with |
290 | 296 | // a null message, other logging frameworks do not support this. |
291 | // see also http://bugzilla.slf4j.org/show_bug.cgi?id=108 | |
297 | // see also http://jira.qos.ch/browse/SLF4J-99 | |
292 | 298 | if (message == null) { |
293 | 299 | message = ""; |
294 | 300 | } |
26 | 26 | import java.util.logging.Handler; |
27 | 27 | import java.util.logging.LogManager; |
28 | 28 | |
29 | import junit.framework.TestCase; | |
30 | ||
31 | 29 | import org.apache.log4j.FileAppender; |
32 | 30 | import org.apache.log4j.PatternLayout; |
31 | import org.junit.After; | |
32 | import org.junit.Before; | |
33 | import org.junit.Test; | |
33 | 34 | import org.slf4j.LoggerFactory; |
34 | ||
35 | public class SLF4JBridgeHandlerPerfTest extends TestCase { | |
35 | public class SLF4JBridgeHandlerPerfTest { | |
36 | 36 | |
37 | 37 | static String LOGGER_NAME = "yay"; |
38 | 38 | static int RUN_LENGTH = 100 * 1000; |
49 | 49 | |
50 | 50 | Handler[] existingHandlers; |
51 | 51 | |
52 | public SLF4JBridgeHandlerPerfTest(String arg0) { | |
53 | super(arg0); | |
54 | } | |
55 | 52 | |
56 | protected void setUp() throws Exception { | |
57 | super.setUp(); | |
53 | @Before | |
54 | public void setUp() throws Exception { | |
58 | 55 | fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log"); |
59 | 56 | |
60 | 57 | existingHandlers = julRootLogger.getHandlers(); |
65 | 62 | log4jRoot.addAppender(fileAppender); |
66 | 63 | } |
67 | 64 | |
68 | protected void tearDown() throws Exception { | |
69 | super.tearDown(); | |
65 | @After | |
66 | public void tearDown() throws Exception { | |
70 | 67 | SLF4JBridgeHandler.uninstall(); |
71 | 68 | fileAppender.close(); |
72 | 69 | log4jRoot.getLoggerRepository().resetConfiguration(); |
93 | 90 | return (end - start) * 1.0 / RUN_LENGTH; |
94 | 91 | } |
95 | 92 | |
93 | @Test | |
96 | 94 | public void testPerf() { |
97 | 95 | SLF4JBridgeHandler.install(); |
98 | 96 |
23 | 23 | */ |
24 | 24 | package org.slf4j.bridge; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
26 | 28 | import java.text.MessageFormat; |
27 | 29 | import java.util.ResourceBundle; |
28 | 30 | import java.util.logging.Level; |
29 | 31 | |
30 | import junit.framework.TestCase; | |
31 | ||
32 | 32 | import org.apache.log4j.spi.LocationInfo; |
33 | 33 | import org.apache.log4j.spi.LoggingEvent; |
34 | ||
35 | public class SLF4JBridgeHandlerTest extends TestCase { | |
34 | import org.junit.After; | |
35 | import org.junit.Before; | |
36 | import org.junit.Test; | |
37 | public class SLF4JBridgeHandlerTest { | |
36 | 38 | |
37 | 39 | static String LOGGER_NAME = "yay"; |
38 | 40 | |
40 | 42 | org.apache.log4j.Logger log4jRoot; |
41 | 43 | java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay"); |
42 | 44 | |
43 | public SLF4JBridgeHandlerTest(String arg0) { | |
44 | super(arg0); | |
45 | } | |
46 | 45 | |
47 | protected void setUp() throws Exception { | |
48 | super.setUp(); | |
46 | @Before | |
47 | public void setUp() throws Exception { | |
49 | 48 | listAppender.extractLocationInfo = true; |
50 | 49 | log4jRoot = org.apache.log4j.Logger.getRootLogger(); |
51 | 50 | log4jRoot.addAppender(listAppender); |
52 | 51 | log4jRoot.setLevel(org.apache.log4j.Level.TRACE); |
53 | 52 | } |
54 | 53 | |
55 | protected void tearDown() throws Exception { | |
56 | super.tearDown(); | |
54 | @After | |
55 | public void tearDown() throws Exception { | |
57 | 56 | SLF4JBridgeHandler.uninstall(); |
58 | 57 | log4jRoot.getLoggerRepository().resetConfiguration(); |
59 | 58 | } |
60 | 59 | |
60 | @Test | |
61 | 61 | public void testSmoke() { |
62 | 62 | SLF4JBridgeHandler.install(); |
63 | 63 | String msg = "msg"; |
77 | 77 | assertEquals("testSmoke", li.getMethodName()); |
78 | 78 | } |
79 | 79 | |
80 | @Test | |
80 | 81 | public void testLevels() { |
81 | 82 | SLF4JBridgeHandler.install(); |
82 | 83 | String msg = "msg"; |
99 | 100 | assertLevel(i++, org.apache.log4j.Level.ERROR); |
100 | 101 | } |
101 | 102 | |
103 | @Test | |
102 | 104 | public void testLogWithResourceBundle() { |
103 | 105 | SLF4JBridgeHandler.install(); |
104 | 106 | |
117 | 119 | assertEquals(expectedMsg, le.getMessage()); |
118 | 120 | } |
119 | 121 | |
122 | @Test | |
120 | 123 | public void testLogWithResourceBundleWithParameters() { |
121 | 124 | SLF4JBridgeHandler.install(); |
122 | 125 | |
162 | 165 | assertEquals(expectedMsg3, le.getMessage()); |
163 | 166 | } |
164 | 167 | |
168 | @Test | |
165 | 169 | public void testLogWithPlaceholderNoParameters() { |
166 | 170 | SLF4JBridgeHandler.install(); |
167 | 171 | String msg = "msg {non-number-string}"; |
173 | 177 | assertEquals(msg, le.getMessage()); |
174 | 178 | } |
175 | 179 | |
180 | // See http://jira.qos.ch/browse/SLF4J-337 | |
181 | ||
182 | @Test | |
183 | public void illFormattedInputShouldBeReturnedAsIs() { | |
184 | SLF4JBridgeHandler.install(); | |
185 | String msg = "foo {18=bad} {0}"; | |
186 | ||
187 | julLogger.log(Level.INFO, msg, "ignored parameter due to IllegalArgumentException"); | |
188 | assertEquals(1, listAppender.list.size()); | |
189 | LoggingEvent le = (LoggingEvent) listAppender.list.get(0); | |
190 | assertEquals(msg, le.getMessage()); | |
191 | } | |
192 | ||
176 | 193 | void assertLevel(int index, org.apache.log4j.Level expectedLevel) { |
177 | 194 | LoggingEvent le = (LoggingEvent) listAppender.list.get(index); |
178 | 195 | assertEquals(expectedLevel, le.getLevel()); |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
1 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
3 | 3 | |
4 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | |
13 | <artifactId>log4j-over-slf4j</artifactId> | |
14 | <packaging>jar</packaging> | |
15 | <name>Log4j Implemented Over SLF4J</name> | |
13 | <artifactId>log4j-over-slf4j</artifactId> | |
14 | <packaging>jar</packaging> | |
15 | <name>Log4j Implemented Over SLF4J</name> | |
16 | 16 | <description>Log4j implemented over SLF4J</description> |
17 | 17 | |
18 | <url>http://www.slf4j.org</url> | |
18 | <url>http://www.slf4j.org</url> | |
19 | 19 | |
20 | 20 | <licenses> |
21 | 21 | <license> |
28 | 28 | <dependency> |
29 | 29 | <groupId>org.slf4j</groupId> |
30 | 30 | <artifactId>slf4j-api</artifactId> |
31 | </dependency> | |
32 | ||
31 | </dependency> | |
33 | 32 | <dependency> |
34 | 33 | <groupId>org.slf4j</groupId> |
35 | 34 | <artifactId>slf4j-jdk14</artifactId> |
36 | 35 | <scope>test</scope> |
37 | </dependency> | |
36 | </dependency> | |
38 | 37 | </dependencies> |
39 | 38 | |
40 | ||
41 | <build> | |
42 | <plugins> | |
43 | ||
44 | <plugin> | |
45 | <groupId>org.apache.maven.plugins</groupId> | |
46 | <artifactId>maven-jar-plugin</artifactId> | |
47 | <configuration> | |
48 | <archive> | |
49 | <manifestEntries> | |
50 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
51 | <Bundle-Description>${project.description}</Bundle-Description> | |
52 | <Implementation-Version>${project.version}</Implementation-Version> | |
53 | </manifestEntries> | |
54 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
55 | </archive> | |
56 | </configuration> | |
57 | </plugin> | |
58 | ||
59 | </plugins> | |
60 | </build> | |
61 | ||
62 | 39 | </project>⏎ |
17 | 17 | |
18 | 18 | import org.apache.log4j.spi.Filter; |
19 | 19 | import org.apache.log4j.spi.ErrorHandler; |
20 | import org.apache.log4j.spi.Layout; | |
21 | 20 | import org.apache.log4j.spi.LoggingEvent; |
22 | 21 | |
23 | 22 | /** |
290 | 290 | log(FQCN, p, msg, t); |
291 | 291 | } |
292 | 292 | |
293 | // See also http://bugzilla.slf4j.org/show_bug.cgi?id=168 | |
293 | // See also http://jira.qos.ch/browse/SLF4J-159 | |
294 | 294 | public void log(String FQCN, Priority p, Object msg, Throwable t) { |
295 | 295 | int levelInt = priorityToLevelInt(p); |
296 | 296 | differentiatedLog(null, FQCN, levelInt, msg, t); |
345 | 345 | public void setLevel(Level level) { |
346 | 346 | // nothing to do |
347 | 347 | } |
348 | ||
349 | public boolean getAdditivity() { | |
350 | return false; | |
351 | } | |
352 | ||
353 | public void assertLog(boolean assertion, String msg) { | |
354 | if(!assertion) | |
355 | error(msg); | |
356 | } | |
348 | 357 | |
349 | 358 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Returns a logger instance created by loggerFactory. This method was requested in |
53 | * <a href="http://bugzilla.slf4j.org/show_bug.cgi?id=234">bug #234</a>. Note that | |
53 | * <a href="http://jira.qos.ch/browse/SLF4J-225">SLF4J-225</a>. Note that | |
54 | 54 | * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this |
55 | 55 | * method is called, the caller must provide his/her own implementation. |
56 | 56 | * |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.log4j.spi; | |
17 | ||
18 | public class Layout { | |
19 | } |
23 | 23 | */ |
24 | 24 | package org.apache.log4j; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
28 | import org.junit.After; | |
29 | import org.junit.Before; | |
30 | import org.junit.Test; | |
27 | 31 | |
28 | 32 | /** |
29 | 33 | * @author Ceki Gücü |
30 | 34 | */ |
31 | public class NDCTest extends TestCase { | |
35 | public class NDCTest { | |
32 | 36 | |
37 | @Before | |
33 | 38 | public void setUp() { |
34 | 39 | assertEquals(0, NDC.getDepth()); |
35 | 40 | } |
36 | 41 | |
42 | @After | |
37 | 43 | public void tearDown() { |
38 | 44 | NDC.clear(); |
39 | 45 | } |
40 | 46 | |
47 | @Test | |
41 | 48 | public void testSmoke() { |
42 | 49 | NDC.push("a"); |
43 | 50 | String back = NDC.pop(); |
44 | 51 | assertEquals("a", back); |
45 | 52 | } |
46 | 53 | |
54 | @Test | |
47 | 55 | public void testPop() { |
48 | 56 | NDC.push("peek"); |
49 | 57 | String back = NDC.peek(); |
50 | 58 | assertEquals("peek", back); |
51 | 59 | } |
52 | 60 | |
61 | @Test | |
53 | 62 | public void testClear() { |
54 | 63 | NDC.push("clear"); |
55 | 64 | NDC.clear(); |
23 | 23 | */ |
24 | 24 | package org.dummy; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
26 | 28 | import java.util.logging.Level; |
27 | 29 | import java.util.logging.LogRecord; |
28 | 30 | |
29 | import junit.framework.TestCase; | |
30 | ||
31 | 31 | import org.apache.log4j.Category; |
32 | 32 | import org.apache.log4j.Logger; |
33 | import org.junit.Test; | |
34 | public class Bug131 { | |
33 | 35 | |
34 | public class Bug131 extends TestCase { | |
35 | ||
36 | @Test | |
36 | 37 | public void testBug131() { |
37 | 38 | |
38 | 39 | ListHandler listHandler = new ListHandler(); |
23 | 23 | */ |
24 | 24 | package org.dummy; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
26 | 28 | import java.util.logging.Level; |
27 | 29 | import java.util.logging.LogRecord; |
28 | 30 | |
29 | import junit.framework.TestCase; | |
30 | ||
31 | 31 | import org.apache.log4j.Category; |
32 | 32 | import org.apache.log4j.Logger; |
33 | import org.junit.Test; | |
33 | 34 | |
34 | public class Bug139 extends TestCase { | |
35 | public class Bug139 { | |
35 | 36 | |
37 | @Test | |
36 | 38 | public void test() { |
37 | 39 | ListHandler listHandler = new ListHandler(); |
38 | 40 | java.util.logging.Logger root = java.util.logging.Logger.getLogger(""); |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
0 | 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
1 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
2 | 3 | |
5 | 6 | <parent> |
6 | 7 | <groupId>org.slf4j</groupId> |
7 | 8 | <artifactId>slf4j-parent</artifactId> |
8 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
9 | 10 | </parent> |
10 | 11 | |
11 | 12 | <artifactId>osgi-over-slf4j</artifactId> |
0 | 0 | <?xml version="1.0" encoding="UTF-8"?> |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <groupId>org.slf4j</groupId> |
8 | 7 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.12</version> | |
8 | <version>1.7.13</version> | |
10 | 9 | |
11 | 10 | <packaging>pom</packaging> |
12 | 11 | <name>SLF4J</name> |
30 | 29 | <scm> |
31 | 30 | <url>https://github.com/ceki/slf4j</url> |
32 | 31 | <connection>git@github.com:qos-ch/slf4j.git</connection> |
33 | </scm> | |
32 | </scm> | |
34 | 33 | |
35 | 34 | <properties> |
35 | <required.jdk.version>1.5</required.jdk.version> | |
36 | <maven.compiler.source>${required.jdk.version}</maven.compiler.source> | |
37 | <maven.compiler.target>${required.jdk.version}</maven.compiler.target> | |
36 | 38 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
37 | <required.jdk.version>1.5</required.jdk.version> | |
39 | <project.build.resourceEncoding>UTF-8</project.build.resourceEncoding> | |
40 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
41 | <!-- used in integration testing --> | |
38 | 42 | <slf4j.api.minimum.compatible.version>1.6.0</slf4j.api.minimum.compatible.version> |
39 | 43 | <cal10n.version>0.8.1</cal10n.version> |
40 | 44 | <log4j.version>1.2.17</log4j.version> |
80 | 84 | </dependency> |
81 | 85 | </dependencies> |
82 | 86 | |
83 | ||
84 | 87 | <dependencyManagement> |
85 | 88 | <dependencies> |
86 | 89 | |
110 | 113 | |
111 | 114 | </dependencies> |
112 | 115 | </dependencyManagement> |
113 | ||
114 | 116 | |
115 | 117 | <build> |
116 | 118 | <extensions> |
123 | 125 | |
124 | 126 | <resources> |
125 | 127 | <resource> |
126 | <directory>src/main/resources</directory> | |
128 | <directory>${project.basedir}/src/main/resources</directory> | |
127 | 129 | <filtering>true</filtering> |
128 | 130 | </resource> |
129 | 131 | </resources> |
130 | 132 | |
133 | <pluginManagement> | |
134 | <plugins> | |
135 | <plugin> | |
136 | <groupId>org.codehaus.mojo</groupId> | |
137 | <artifactId>animal-sniffer-maven-plugin</artifactId> | |
138 | <version>1.14</version> | |
139 | <configuration> | |
140 | <signature> | |
141 | <groupId>org.codehaus.mojo.signature</groupId> | |
142 | <artifactId>java15</artifactId> | |
143 | <version>1.0</version> | |
144 | </signature> | |
145 | </configuration> | |
146 | </plugin> | |
147 | </plugins> | |
148 | </pluginManagement> | |
149 | ||
131 | 150 | <plugins> |
151 | ||
132 | 152 | <plugin> |
133 | 153 | <groupId>org.apache.maven.plugins</groupId> |
134 | 154 | <artifactId>maven-compiler-plugin</artifactId> |
135 | <version>2.3.2</version> | |
155 | <version>3.3</version> | |
136 | 156 | <configuration> |
137 | <source>1.5</source> | |
138 | <target>1.5</target> | |
157 | <source>${required.jdk.version}</source> | |
158 | <target>${required.jdk.version}</target> | |
139 | 159 | </configuration> |
140 | 160 | </plugin> |
141 | 161 | |
143 | 163 | <groupId>org.apache.maven.plugins</groupId> |
144 | 164 | <artifactId>maven-jar-plugin</artifactId> |
145 | 165 | <version>2.3.1</version> |
166 | <configuration> | |
167 | <archive> | |
168 | <manifestEntries> | |
169 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
170 | <Bundle-Description>${project.description}</Bundle-Description> | |
171 | <X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK> | |
172 | <X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK> | |
173 | <Implementation-Version>${project.version}</Implementation-Version> | |
174 | </manifestEntries> | |
175 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
176 | </archive> | |
177 | <skipIfEmpty>true</skipIfEmpty> | |
178 | </configuration> | |
146 | 179 | </plugin> |
147 | 180 | |
148 | 181 | <plugin> |
188 | 221 | </configuration> |
189 | 222 | </plugin> |
190 | 223 | |
191 | <!-- as suggested in http://bugzilla.slf4j.org/show_bug.cgi?id=152 --> | |
224 | <!-- as suggested in http://jira.qos.ch/browse/SLF4J-143 --> | |
192 | 225 | <plugin> |
193 | 226 | <groupId>org.codehaus.mojo</groupId> |
194 | 227 | <artifactId>build-helper-maven-plugin</artifactId> |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
1 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
3 | ||
4 | <modelVersion>4.0.0</modelVersion> | |
3 | 5 | |
4 | 6 | <parent> |
5 | 7 | <groupId>org.slf4j</groupId> |
6 | 8 | <artifactId>slf4j-parent</artifactId> |
7 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
8 | 10 | </parent> |
9 | ||
10 | <modelVersion>4.0.0</modelVersion> | |
11 | 11 | |
12 | 12 | <artifactId>slf4j-android</artifactId> |
13 | 13 | <packaging>jar</packaging> |
30 | 30 | </dependency> |
31 | 31 | </dependencies> |
32 | 32 | |
33 | <build> | |
34 | <plugins> | |
35 | <plugin> | |
36 | <groupId>org.apache.maven.plugins</groupId> | |
37 | <artifactId>maven-jar-plugin</artifactId> | |
38 | <configuration> | |
39 | <archive> | |
40 | <manifestEntries> | |
41 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
42 | <Bundle-Description>${project.description}</Bundle-Description> | |
43 | <Implementation-Version>${project.version}</Implementation-Version> | |
44 | </manifestEntries> | |
45 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
46 | </archive> | |
47 | </configuration> | |
48 | </plugin> | |
49 | ||
50 | <plugin> | |
51 | <!-- Google Android requires class compatibility set to 5.0 --> | |
52 | <groupId>org.apache.maven.plugins</groupId> | |
53 | <artifactId>maven-compiler-plugin</artifactId> | |
54 | <configuration> | |
55 | <source>${required.jdk.version}</source> | |
56 | <target>${required.jdk.version}</target> | |
57 | </configuration> | |
58 | </plugin> | |
59 | </plugins> | |
60 | </build> | |
61 | ||
62 | 33 | </project>⏎ |
529 | 529 | private void formatAndLog(int priority, String format, Object... argArray) { |
530 | 530 | if (isLoggable(priority)) { |
531 | 531 | FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray); |
532 | _log(priority, ft.getMessage(), ft.getThrowable()); | |
532 | logInternal(priority, ft.getMessage(), ft.getThrowable()); | |
533 | 533 | } |
534 | 534 | } |
535 | 535 | |
536 | 536 | private void log(int priority, String message, Throwable throwable) { |
537 | 537 | if (isLoggable(priority)) { |
538 | _log(priority, message, throwable); | |
538 | logInternal(priority, message, throwable); | |
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
543 | 543 | return Log.isLoggable(name, priority); |
544 | 544 | } |
545 | 545 | |
546 | private void _log(int priority, String message, Throwable throwable) { | |
546 | private void logInternal(int priority, String message, Throwable throwable) { | |
547 | 547 | if (throwable != null) { |
548 | 548 | message += '\n' + Log.getStackTraceString(throwable); |
549 | 549 | } |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
1 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
3 | 3 | |
4 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-api</artifactId> |
17 | 17 | |
18 | 18 | <url>http://www.slf4j.org</url> |
19 | 19 | |
20 | <dependencies> | |
21 | </dependencies> | |
22 | ||
23 | 20 | <build> |
24 | 21 | <plugins> |
22 | <plugin> | |
23 | <groupId>org.codehaus.mojo</groupId> | |
24 | <artifactId>animal-sniffer-maven-plugin</artifactId> | |
25 | <configuration> | |
26 | <!-- Signatures cannot be determined and will error unless excluded. This is isolated to | |
27 | code otherwise already marked for removal in the module artifact. --> | |
28 | <ignores> | |
29 | <ignore>org.slf4j.impl.StaticMDCBinder</ignore> | |
30 | <ignore>org.slf4j.impl.StaticLoggerBinder</ignore> | |
31 | <ignore>org.slf4j.impl.StaticMarkerBinder</ignore> | |
32 | </ignores> | |
33 | </configuration> | |
34 | </plugin> | |
25 | 35 | <plugin> |
26 | 36 | <groupId>org.apache.maven.plugins</groupId> |
27 | 37 | <artifactId>maven-surefire-plugin</artifactId> |
39 | 49 | <plugin> |
40 | 50 | <groupId>org.apache.maven.plugins</groupId> |
41 | 51 | <artifactId>maven-jar-plugin</artifactId> |
42 | <configuration> | |
43 | <archive> | |
44 | <manifestEntries> | |
45 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
46 | <Bundle-Description>${project.description}</Bundle-Description> | |
47 | <Implementation-Version>${project.version}</Implementation-Version> | |
48 | </manifestEntries> | |
49 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
50 | </archive> | |
51 | </configuration> | |
52 | 52 | <executions> |
53 | 53 | <execution> |
54 | 54 | <id>bundle-test-jar</id> |
79 | 79 | </tasks> |
80 | 80 | </configuration> |
81 | 81 | </plugin> |
82 | ||
83 | 82 | </plugins> |
84 | 83 | |
85 | 84 | </build> |
27 | 27 | import java.net.URL; |
28 | 28 | import java.util.Arrays; |
29 | 29 | import java.util.Enumeration; |
30 | import java.util.Iterator; | |
31 | 30 | import java.util.LinkedHashSet; |
32 | 31 | import java.util.List; |
33 | 32 | import java.util.Set; |
84 | 83 | |
85 | 84 | // Support for detecting mismatched logger names. |
86 | 85 | static final String DETECT_LOGGER_NAME_MISMATCH_PROPERTY = "slf4j.detectLoggerNameMismatch"; |
87 | static boolean DETECT_LOGGER_NAME_MISMATCH = Boolean.getBoolean(DETECT_LOGGER_NAME_MISMATCH_PROPERTY); | |
86 | static boolean DETECT_LOGGER_NAME_MISMATCH = Util.safeGetBooleanSystemProperty(DETECT_LOGGER_NAME_MISMATCH_PROPERTY); | |
88 | 87 | |
89 | 88 | /** |
90 | 89 | * It is LoggerFactory's responsibility to track version changes and manage |
125 | 124 | private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg) { |
126 | 125 | if (msg == null) |
127 | 126 | return false; |
128 | if (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) | |
127 | if (msg.contains("org/slf4j/impl/StaticLoggerBinder")) | |
129 | 128 | return true; |
130 | if (msg.indexOf("org.slf4j.impl.StaticLoggerBinder") != -1) | |
129 | if (msg.contains("org.slf4j.impl.StaticLoggerBinder")) | |
131 | 130 | return true; |
132 | 131 | return false; |
133 | 132 | } |
154 | 153 | } |
155 | 154 | } catch (java.lang.NoSuchMethodError nsme) { |
156 | 155 | String msg = nsme.getMessage(); |
157 | if (msg != null && msg.indexOf("org.slf4j.impl.StaticLoggerBinder.getSingleton()") != -1) { | |
156 | if (msg != null && msg.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) { | |
158 | 157 | INITIALIZATION_STATE = FAILED_INITIALIZATION; |
159 | 158 | Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding."); |
160 | 159 | Util.report("Your binding is version 1.5.5 or earlier."); |
197 | 196 | String requested = StaticLoggerBinder.REQUESTED_API_VERSION; |
198 | 197 | |
199 | 198 | boolean match = false; |
200 | for (int i = 0; i < API_COMPATIBILITY_LIST.length; i++) { | |
201 | if (requested.startsWith(API_COMPATIBILITY_LIST[i])) { | |
199 | for (String aAPI_COMPATIBILITY_LIST : API_COMPATIBILITY_LIST) { | |
200 | if (requested.startsWith(aAPI_COMPATIBILITY_LIST)) { | |
202 | 201 | match = true; |
203 | 202 | } |
204 | 203 | } |
235 | 234 | paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH); |
236 | 235 | } |
237 | 236 | while (paths.hasMoreElements()) { |
238 | URL path = (URL) paths.nextElement(); | |
237 | URL path = paths.nextElement(); | |
239 | 238 | staticLoggerBinderPathSet.add(path); |
240 | 239 | } |
241 | 240 | } catch (IOException ioe) { |
256 | 255 | private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) { |
257 | 256 | if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) { |
258 | 257 | Util.report("Class path contains multiple SLF4J bindings."); |
259 | Iterator<URL> iterator = staticLoggerBinderPathSet.iterator(); | |
260 | while (iterator.hasNext()) { | |
261 | URL path = (URL) iterator.next(); | |
258 | for (URL path : staticLoggerBinderPathSet) { | |
262 | 259 | Util.report("Found binding in [" + path + "]"); |
263 | 260 | } |
264 | 261 | Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation."); |
303 | 300 | Logger logger = getLogger(clazz.getName()); |
304 | 301 | if (DETECT_LOGGER_NAME_MISMATCH) { |
305 | 302 | Class<?> autoComputedCallingClass = Util.getCallingClass(); |
306 | if (nonMatchingClasses(clazz, autoComputedCallingClass)) { | |
303 | if (autoComputedCallingClass != null && nonMatchingClasses(clazz, autoComputedCallingClass)) { | |
307 | 304 | Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", logger.getName(), |
308 | 305 | autoComputedCallingClass.getName())); |
309 | 306 | Util.report("See " + LOGGER_NAME_MISMATCH_URL + " for an explanation"); |
338 | 335 | throw new IllegalStateException(UNSUCCESSFUL_INIT_MSG); |
339 | 336 | case ONGOING_INITIALIZATION: |
340 | 337 | // support re-entrant behavior. |
341 | // See also http://bugzilla.slf4j.org/show_bug.cgi?id=106 | |
338 | // See also http://jira.qos.ch/browse/SLF4J-97 | |
342 | 339 | return TEMP_FACTORY; |
343 | 340 | } |
344 | 341 | throw new IllegalStateException("Unreachable code"); |
90 | 90 | } catch (NoClassDefFoundError ncde) { |
91 | 91 | mdcAdapter = new NOPMDCAdapter(); |
92 | 92 | String msg = ncde.getMessage(); |
93 | if (msg != null && msg.indexOf("StaticMDCBinder") != -1) { | |
93 | if (msg != null && msg.contains("StaticMDCBinder")) { | |
94 | 94 | Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\"."); |
95 | 95 | Util.report("Defaulting to no-operation MDCAdapter implementation."); |
96 | 96 | Util.report("See " + NO_STATIC_MDC_BINDER_URL + " for further details."); |
31 | 31 | /** |
32 | 32 | * Basic MDC implementation, which can be used with logging systems that lack |
33 | 33 | * out-of-the-box MDC support. |
34 | * | |
34 | * | |
35 | 35 | * This code was initially inspired by logback's LogbackMDCAdapter. However, |
36 | 36 | * LogbackMDCAdapter has evolved and is now considerably more sophisticated. |
37 | 37 | * |
38 | 38 | * @author Ceki Gulcu |
39 | 39 | * @author Maarten Bosteels |
40 | * @author Lukasz Cwik | |
40 | 41 | * |
41 | 42 | * @since 1.5.0 |
42 | 43 | */ |
43 | 44 | public class BasicMDCAdapter implements MDCAdapter { |
44 | 45 | |
45 | private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal = new InheritableThreadLocal<Map<String, String>>(); | |
46 | ||
47 | static boolean isJDK14() { | |
48 | try { | |
49 | String javaVersion = System.getProperty("java.version"); | |
50 | return javaVersion.startsWith("1.4"); | |
51 | } catch (SecurityException se) { | |
52 | // punt and assume JDK 1.5 or later | |
53 | return false; | |
46 | private InheritableThreadLocal<Map<String, String>> inheritableThreadLocal = | |
47 | new InheritableThreadLocal<Map<String, String>>() { | |
48 | @Override | |
49 | protected Map<String,String> childValue(Map<String,String> parentValue) { | |
50 | if (parentValue == null) { | |
51 | return null; | |
52 | } | |
53 | return new HashMap<String, String>(parentValue); | |
54 | 54 | } |
55 | } | |
56 | ||
57 | static boolean IS_JDK14 = isJDK14(); | |
55 | }; | |
58 | 56 | |
59 | 57 | /** |
60 | 58 | * Put a context value (the <code>val</code> parameter) as identified with |
61 | 59 | * the <code>key</code> parameter into the current thread's context map. |
62 | 60 | * Note that contrary to log4j, the <code>val</code> parameter can be null. |
63 | * | |
61 | * | |
64 | 62 | * <p> |
65 | 63 | * If the current thread does not have a context map it is created as a side |
66 | 64 | * effect of this call. |
67 | * | |
65 | * | |
68 | 66 | * @throws IllegalArgumentException |
69 | 67 | * in case the "key" parameter is null |
70 | 68 | */ |
72 | 70 | if (key == null) { |
73 | 71 | throw new IllegalArgumentException("key cannot be null"); |
74 | 72 | } |
75 | Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get(); | |
73 | Map<String, String> map = inheritableThreadLocal.get(); | |
76 | 74 | if (map == null) { |
77 | map = Collections.<String, String> synchronizedMap(new HashMap<String, String>()); | |
75 | map = new HashMap<String, String>(); | |
78 | 76 | inheritableThreadLocal.set(map); |
79 | 77 | } |
80 | 78 | map.put(key, val); |
84 | 82 | * Get the context identified by the <code>key</code> parameter. |
85 | 83 | */ |
86 | 84 | public String get(String key) { |
87 | Map<String, String> Map = (Map<String, String>) inheritableThreadLocal.get(); | |
88 | if ((Map != null) && (key != null)) { | |
89 | return (String) Map.get(key); | |
85 | Map<String, String> map = inheritableThreadLocal.get(); | |
86 | if ((map != null) && (key != null)) { | |
87 | return map.get(key); | |
90 | 88 | } else { |
91 | 89 | return null; |
92 | 90 | } |
96 | 94 | * Remove the the context identified by the <code>key</code> parameter. |
97 | 95 | */ |
98 | 96 | public void remove(String key) { |
99 | Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get(); | |
97 | Map<String, String> map = inheritableThreadLocal.get(); | |
100 | 98 | if (map != null) { |
101 | 99 | map.remove(key); |
102 | 100 | } |
106 | 104 | * Clear all entries in the MDC. |
107 | 105 | */ |
108 | 106 | public void clear() { |
109 | Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get(); | |
107 | Map<String, String> map = inheritableThreadLocal.get(); | |
110 | 108 | if (map != null) { |
111 | 109 | map.clear(); |
112 | // the InheritableThreadLocal.remove method was introduced in JDK 1.5 | |
113 | // Thus, invoking clear() on previous JDK 1.4 will fail | |
114 | if (isJDK14()) { | |
115 | inheritableThreadLocal.set(null); | |
116 | } else { | |
117 | inheritableThreadLocal.remove(); | |
118 | } | |
110 | inheritableThreadLocal.remove(); | |
119 | 111 | } |
120 | 112 | } |
121 | 113 | |
122 | 114 | /** |
123 | 115 | * Returns the keys in the MDC as a {@link Set} of {@link String}s The |
124 | 116 | * returned value can be null. |
125 | * | |
117 | * | |
126 | 118 | * @return the keys in the MDC |
127 | 119 | */ |
128 | 120 | public Set<String> getKeys() { |
129 | Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get(); | |
121 | Map<String, String> map = inheritableThreadLocal.get(); | |
130 | 122 | if (map != null) { |
131 | 123 | return map.keySet(); |
132 | 124 | } else { |
135 | 127 | } |
136 | 128 | |
137 | 129 | /** |
138 | * Return a copy of the current thread's context map. | |
130 | * Return a copy of the current thread's context map. | |
139 | 131 | * Returned value may be null. |
140 | * | |
132 | * | |
141 | 133 | */ |
142 | 134 | public Map<String, String> getCopyOfContextMap() { |
143 | Map<String, String> oldMap = (Map<String, String>) inheritableThreadLocal.get(); | |
135 | Map<String, String> oldMap = inheritableThreadLocal.get(); | |
144 | 136 | if (oldMap != null) { |
145 | Map<String, String> newMap = Collections.<String, String> synchronizedMap(new HashMap<String, String>()); | |
146 | synchronized (oldMap) { | |
147 | newMap.putAll(oldMap); | |
148 | } | |
149 | return newMap; | |
137 | return new HashMap<String, String>(oldMap); | |
150 | 138 | } else { |
151 | 139 | return null; |
152 | 140 | } |
153 | 141 | } |
154 | 142 | |
155 | 143 | public void setContextMap(Map<String, String> contextMap) { |
156 | Map<String, String> map = Collections.<String, String> synchronizedMap(new HashMap<String, String>(contextMap)); | |
157 | inheritableThreadLocal.set(map); | |
144 | inheritableThreadLocal.set(new HashMap<String, String>(contextMap)); | |
158 | 145 | } |
159 | ||
160 | 146 | } |
100 | 100 | |
101 | 101 | int size = referenceList.size(); |
102 | 102 | for (int i = 0; i < size; i++) { |
103 | Marker m = (Marker) referenceList.get(i); | |
103 | Marker m = referenceList.get(i); | |
104 | 104 | if (referenceToRemove.equals(m)) { |
105 | 105 | referenceList.remove(i); |
106 | 106 | return true; |
119 | 119 | } |
120 | 120 | |
121 | 121 | if (hasReferences()) { |
122 | for (int i = 0; i < referenceList.size(); i++) { | |
123 | Marker ref = (Marker) referenceList.get(i); | |
122 | for (Marker ref : referenceList) { | |
124 | 123 | if (ref.contains(other)) { |
125 | 124 | return true; |
126 | 125 | } |
142 | 141 | } |
143 | 142 | |
144 | 143 | if (hasReferences()) { |
145 | for (int i = 0; i < referenceList.size(); i++) { | |
146 | Marker ref = (Marker) referenceList.get(i); | |
144 | for (Marker ref : referenceList) { | |
147 | 145 | if (ref.contains(name)) { |
148 | 146 | return true; |
149 | 147 | } |
181 | 179 | StringBuilder sb = new StringBuilder(this.getName()); |
182 | 180 | sb.append(' ').append(OPEN); |
183 | 181 | while (it.hasNext()) { |
184 | reference = (Marker) it.next(); | |
182 | reference = it.next(); | |
185 | 183 | sb.append(reference.getName()); |
186 | 184 | if (it.hasNext()) { |
187 | 185 | sb.append(SEP); |
202 | 202 | return new FormattingTuple(messagePattern, argArray, throwableCandidate); |
203 | 203 | } else { // add the tail string which contains no variables and return |
204 | 204 | // the result. |
205 | sbuf.append(messagePattern.substring(i, messagePattern.length())); | |
205 | sbuf.append(messagePattern, i, messagePattern.length()); | |
206 | 206 | return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate); |
207 | 207 | } |
208 | 208 | } else { |
209 | 209 | if (isEscapedDelimeter(messagePattern, j)) { |
210 | 210 | if (!isDoubleEscaped(messagePattern, j)) { |
211 | 211 | L--; // DELIM_START was escaped, thus should not be incremented |
212 | sbuf.append(messagePattern.substring(i, j - 1)); | |
212 | sbuf.append(messagePattern, i, j - 1); | |
213 | 213 | sbuf.append(DELIM_START); |
214 | 214 | i = j + 1; |
215 | 215 | } else { |
216 | 216 | // The escape character preceding the delimiter start is |
217 | 217 | // itself escaped: "abc x:\\{}" |
218 | 218 | // we have to consume one backward slash |
219 | sbuf.append(messagePattern.substring(i, j - 1)); | |
219 | sbuf.append(messagePattern, i, j - 1); | |
220 | 220 | deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>()); |
221 | 221 | i = j + 2; |
222 | 222 | } |
223 | 223 | } else { |
224 | 224 | // normal case |
225 | sbuf.append(messagePattern.substring(i, j)); | |
225 | sbuf.append(messagePattern, i, j); | |
226 | 226 | deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>()); |
227 | 227 | i = j + 2; |
228 | 228 | } |
229 | 229 | } |
230 | 230 | } |
231 | 231 | // append the characters following the last {} pair. |
232 | sbuf.append(messagePattern.substring(i, messagePattern.length())); | |
232 | sbuf.append(messagePattern, i, messagePattern.length()); | |
233 | 233 | if (L < argArray.length - 1) { |
234 | 234 | return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate); |
235 | 235 | } else { |
34 | 34 | private Util() { |
35 | 35 | } |
36 | 36 | |
37 | public static String safeGetSystemProperty(String key) { | |
38 | if (key == null) | |
39 | throw new IllegalArgumentException("null input"); | |
40 | ||
41 | String result = null; | |
42 | try { | |
43 | result = System.getProperty(key); | |
44 | } catch (java.lang.SecurityException sm) { | |
45 | ; // ignore | |
46 | } | |
47 | return result; | |
48 | } | |
49 | ||
50 | public static boolean safeGetBooleanSystemProperty(String key) { | |
51 | String value = safeGetSystemProperty(key); | |
52 | if (value == null) | |
53 | return false; | |
54 | else | |
55 | return value.equalsIgnoreCase("true"); | |
56 | } | |
57 | ||
37 | 58 | /** |
38 | 59 | * In order to call {@link SecurityManager#getClassContext()}, which is a |
39 | 60 | * protected method, we add this wrapper which allows the method to be visible |
45 | 66 | } |
46 | 67 | } |
47 | 68 | |
48 | private static final ClassContextSecurityManager SECURITY_MANAGER = new ClassContextSecurityManager(); | |
69 | private static ClassContextSecurityManager SECURITY_MANAGER; | |
70 | private static boolean SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = false; | |
71 | ||
72 | private static ClassContextSecurityManager getSecurityManager() { | |
73 | if(SECURITY_MANAGER != null) | |
74 | return SECURITY_MANAGER; | |
75 | else if(SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED) | |
76 | return null; | |
77 | else { | |
78 | SECURITY_MANAGER = safeCreateSecurityManager(); | |
79 | SECURITY_MANAGER_CREATION_ALREADY_ATTEMPTED = true; | |
80 | return SECURITY_MANAGER; | |
81 | } | |
82 | } | |
83 | ||
84 | private static ClassContextSecurityManager safeCreateSecurityManager() { | |
85 | try { | |
86 | return new ClassContextSecurityManager(); | |
87 | } catch (java.lang.SecurityException sm) { | |
88 | return null; | |
89 | } | |
90 | } | |
49 | 91 | |
50 | 92 | /** |
51 | 93 | * Returns the name of the class which called the invoking method. |
53 | 95 | * @return the name of the class which called the invoking method. |
54 | 96 | */ |
55 | 97 | public static Class<?> getCallingClass() { |
56 | Class<?>[] trace = SECURITY_MANAGER.getClassContext(); | |
98 | ClassContextSecurityManager securityManager = getSecurityManager(); | |
99 | if(securityManager == null) | |
100 | return null; | |
101 | Class<?>[] trace = securityManager.getClassContext(); | |
57 | 102 | String thisClassName = Util.class.getName(); |
58 | 103 | |
59 | 104 | // Advance until Util is found |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import static org.junit.Assert.*; | |
27 | ||
26 | 28 | import java.util.Iterator; |
27 | 29 | |
28 | import junit.framework.TestCase; | |
29 | ||
30 | import org.junit.Test; | |
30 | 31 | import org.slf4j.helpers.BasicMarkerFactory; |
31 | 32 | |
32 | 33 | /** |
35 | 36 | * @author Ceki Gülcü |
36 | 37 | * @author Joern Huxhorn |
37 | 38 | */ |
38 | public class BasicMarkerTest extends TestCase { | |
39 | public class BasicMarkerTest { | |
39 | 40 | static final String BLUE_STR = "BLUE"; |
40 | 41 | static final String RED_STR = "RED"; |
41 | 42 | static final String GREEN_STR = "GREEN"; |
68 | 69 | multiComp.add(comp); |
69 | 70 | } |
70 | 71 | |
72 | @Test | |
71 | 73 | public void testPrimitive() { |
72 | 74 | assertEquals(BLUE_STR, blue.getName()); |
73 | 75 | assertTrue(blue.contains(blue)); |
79 | 81 | assertTrue(blue2.contains(blue)); |
80 | 82 | } |
81 | 83 | |
84 | @Test | |
82 | 85 | public void testPrimitiveByName() { |
83 | 86 | assertTrue(blue.contains(BLUE_STR)); |
84 | 87 | } |
85 | 88 | |
89 | @Test | |
86 | 90 | public void testComposite() { |
87 | 91 | assertTrue(comp.contains(comp)); |
88 | 92 | assertTrue(comp.contains(blue)); |
89 | 93 | } |
90 | 94 | |
95 | @Test | |
91 | 96 | public void testCompositeByName() { |
92 | 97 | assertTrue(comp.contains(COMP_STR)); |
93 | 98 | assertTrue(comp.contains(BLUE_STR)); |
94 | 99 | } |
95 | 100 | |
101 | @Test | |
96 | 102 | public void testMultiComposite() { |
97 | 103 | assertTrue(multiComp.contains(comp)); |
98 | 104 | assertTrue(multiComp.contains(blue)); |
100 | 106 | assertFalse(multiComp.contains(red)); |
101 | 107 | } |
102 | 108 | |
109 | @Test | |
103 | 110 | public void testMultiCompositeByName() { |
104 | 111 | assertTrue(multiComp.contains(COMP_STR)); |
105 | 112 | assertTrue(multiComp.contains(BLUE_STR)); |
107 | 114 | assertFalse(multiComp.contains(RED_STR)); |
108 | 115 | } |
109 | 116 | |
117 | @Test | |
110 | 118 | public void testMultiAdd() { |
111 | 119 | Marker parent = factory.getMarker(PARENT_MARKER_STR); |
112 | 120 | Marker child = factory.getMarker(CHILD_MARKER_STR); |
121 | 129 | assertFalse(iterator.hasNext()); |
122 | 130 | } |
123 | 131 | |
132 | @Test | |
124 | 133 | public void testAddRemove() { |
125 | 134 | final String NEW_PREFIX = "NEW_"; |
126 | 135 | Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR); |
141 | 150 | assertFalse(parent.remove(child)); |
142 | 151 | } |
143 | 152 | |
153 | @Test | |
144 | 154 | public void testSelfRecursion() { |
145 | 155 | final String diffPrefix = "NEW_" + diff; |
146 | 156 | final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; |
154 | 164 | assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR)); |
155 | 165 | } |
156 | 166 | |
167 | @Test | |
157 | 168 | public void testIndirectRecursion() { |
158 | 169 | final String diffPrefix = "NEW_" + diff; |
159 | 170 | final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; |
174 | 185 | assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR)); |
175 | 186 | } |
176 | 187 | |
188 | @Test | |
177 | 189 | public void testHomonyms() { |
178 | 190 | final String diffPrefix = "homonym" + diff; |
179 | 191 | final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR; |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import static org.junit.Assert.assertNull; | |
27 | import static org.junit.Assert.assertTrue; | |
28 | ||
26 | 29 | import java.util.Random; |
27 | 30 | |
31 | import org.junit.Test; | |
28 | 32 | import org.slf4j.helpers.BasicMarker; |
29 | 33 | import org.slf4j.helpers.NOPLogger; |
30 | 34 | |
31 | import junit.framework.TestCase; | |
32 | ||
33 | public class NoBindingTest extends TestCase { | |
35 | public class NoBindingTest { | |
34 | 36 | |
35 | 37 | int diff = new Random().nextInt(10000); |
36 | 38 | |
39 | @Test | |
37 | 40 | public void testLogger() { |
38 | 41 | Logger logger = LoggerFactory.getLogger(NoBindingTest.class); |
39 | 42 | logger.debug("hello" + diff); |
40 | 43 | assertTrue(logger instanceof NOPLogger); |
41 | 44 | } |
42 | 45 | |
43 | public void testMDC() { | |
46 | @Test | |
47 | public void testMDC() { | |
44 | 48 | MDC.put("k" + diff, "v"); |
45 | 49 | assertNull(MDC.get("k")); |
46 | 50 | } |
47 | 51 | |
52 | @Test | |
48 | 53 | public void testMarker() { |
49 | 54 | Marker m = MarkerFactory.getMarker("a" + diff); |
50 | 55 | assertTrue(m instanceof BasicMarker); |
0 | /** | |
1 | * Copyright (c) 2004-2013 QOS.ch, Copyright (C) 2015 Google Inc. | |
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.helpers; | |
25 | ||
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertFalse; | |
28 | import static org.junit.Assert.assertNull; | |
29 | import static org.junit.Assert.fail; | |
30 | ||
31 | import java.lang.Thread.UncaughtExceptionHandler; | |
32 | import java.util.Map; | |
33 | ||
34 | import org.junit.After; | |
35 | import org.junit.Test; | |
36 | import org.slf4j.spi.MDCAdapter; | |
37 | ||
38 | /** | |
39 | * Tests for {@link BasicMDCAdapter} | |
40 | * | |
41 | * @author Lukasz Cwik | |
42 | */ | |
43 | public class BasicMDCAdapterTest { | |
44 | MDCAdapter mdc = new BasicMDCAdapter(); | |
45 | ||
46 | @After | |
47 | public void tearDown() throws Exception { | |
48 | mdc.clear(); | |
49 | } | |
50 | ||
51 | @Test | |
52 | public void testSettingAndGettingWithMDC() { | |
53 | assertNull(mdc.get("testKey")); | |
54 | mdc.put("testKey", "testValue"); | |
55 | assertEquals(mdc.get("testKey"), "testValue"); | |
56 | } | |
57 | ||
58 | @Test | |
59 | public void testOverwritingAKeyInMDC() { | |
60 | assertNull(mdc.get("testKey")); | |
61 | mdc.put("testKey", "testValue"); | |
62 | mdc.put("testKey", "differentTestValue"); | |
63 | assertEquals(mdc.get("testKey"), "differentTestValue"); | |
64 | } | |
65 | ||
66 | @Test | |
67 | public void testClearingMDC() { | |
68 | mdc.put("testKey", "testValue"); | |
69 | assertFalse(mdc.getCopyOfContextMap().isEmpty()); | |
70 | mdc.clear(); | |
71 | assertNull(mdc.getCopyOfContextMap()); | |
72 | } | |
73 | ||
74 | @Test | |
75 | public void testGetCopyOfContextMapFromMDC() { | |
76 | mdc.put("testKey", "testValue"); | |
77 | Map<String, String> copy = mdc.getCopyOfContextMap(); | |
78 | mdc.put("anotherTestKey", "anotherTestValue"); | |
79 | assertFalse(copy.size() == mdc.getCopyOfContextMap().size()); | |
80 | } | |
81 | ||
82 | @Test | |
83 | public void testMDCInheritsValuesFromParentThread() throws Exception { | |
84 | mdc.put("parentKey", "parentValue"); | |
85 | runAndWait(new Runnable() { | |
86 | public void run() { | |
87 | mdc.put("childKey", "childValue"); | |
88 | assertEquals("parentValue", mdc.get("parentKey")); | |
89 | } | |
90 | }); | |
91 | } | |
92 | ||
93 | @Test | |
94 | public void testMDCDoesntGetValuesFromChildThread() throws Exception { | |
95 | mdc.put("parentKey", "parentValue"); | |
96 | runAndWait(new Runnable() { | |
97 | public void run() { | |
98 | mdc.put("childKey", "childValue"); | |
99 | } | |
100 | }); | |
101 | assertEquals("parentValue", mdc.get("parentKey")); | |
102 | assertNull(mdc.get("childKey")); | |
103 | } | |
104 | ||
105 | @Test | |
106 | public void testMDCChildThreadCanOverwriteParentThread() throws Exception { | |
107 | mdc.put("sharedKey", "parentValue"); | |
108 | runAndWait(new Runnable() { | |
109 | public void run() { | |
110 | assertEquals("parentValue", mdc.get("sharedKey")); | |
111 | mdc.put("sharedKey", "childValue"); | |
112 | assertEquals("childValue", mdc.get("sharedKey")); | |
113 | } | |
114 | }); | |
115 | assertEquals("parentValue", mdc.get("sharedKey")); | |
116 | } | |
117 | ||
118 | private void runAndWait(Runnable runnable) throws Exception { | |
119 | RecordingExceptionHandler handler = new RecordingExceptionHandler(); | |
120 | Thread thread = new Thread(runnable); | |
121 | thread.setUncaughtExceptionHandler(handler); | |
122 | thread.start(); | |
123 | try { | |
124 | thread.join(); | |
125 | } catch (Throwable t) { | |
126 | fail("Unexpected failure in child thread:" + t.getMessage()); | |
127 | } | |
128 | assertFalse(handler.getMessage(), handler.hadException()); | |
129 | } | |
130 | ||
131 | /** A {@link UncaughtExceptionHandler} that records whether the thread threw an exception. */ | |
132 | private static class RecordingExceptionHandler implements UncaughtExceptionHandler { | |
133 | private Throwable exception; | |
134 | ||
135 | public void uncaughtException(Thread t, Throwable e) { | |
136 | exception = e; | |
137 | } | |
138 | ||
139 | boolean hadException() { | |
140 | return exception != null; | |
141 | } | |
142 | ||
143 | String getMessage() { | |
144 | return exception != null ? exception.getMessage() : ""; | |
145 | } | |
146 | } | |
147 | } |
23 | 23 | */ |
24 | 24 | package org.slf4j.helpers; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertTrue; | |
28 | ||
26 | 29 | import java.util.Arrays; |
27 | 30 | import java.util.Random; |
28 | 31 | |
29 | import junit.framework.TestCase; | |
32 | import org.junit.Test; | |
30 | 33 | |
31 | 34 | /** |
32 | 35 | * Test that our BubbleSort algorithm is correctly implemented. |
34 | 37 | * @author Ceki |
35 | 38 | * |
36 | 39 | */ |
37 | public class BubbleSortTest extends TestCase { | |
40 | public class BubbleSortTest { | |
38 | 41 | |
42 | @Test | |
39 | 43 | public void testSmoke() { |
40 | 44 | int[] a = new int[] { 5, 3, 2, 7 }; |
41 | 45 | BubbleSort.sort(a); |
46 | 50 | assertEquals(7, a[i++]); |
47 | 51 | } |
48 | 52 | |
53 | @Test | |
49 | 54 | public void testEmpty() { |
50 | 55 | int[] a = new int[] {}; |
51 | 56 | BubbleSort.sort(a); |
52 | 57 | } |
53 | 58 | |
59 | @Test | |
54 | 60 | public void testSorted() { |
55 | 61 | int[] a = new int[] { 3, 30, 300, 3000 }; |
56 | 62 | BubbleSort.sort(a); |
61 | 67 | assertEquals(3000, a[i++]); |
62 | 68 | } |
63 | 69 | |
70 | @Test | |
64 | 71 | public void testInverted() { |
65 | 72 | int[] a = new int[] { 3000, 300, 30, 3 }; |
66 | 73 | BubbleSort.sort(a); |
71 | 78 | assertEquals(3000, a[i++]); |
72 | 79 | } |
73 | 80 | |
81 | @Test | |
74 | 82 | public void testWithSameEntry() { |
75 | 83 | int[] a = new int[] { 10, 20, 10, 20 }; |
76 | 84 | BubbleSort.sort(a); |
81 | 89 | assertEquals(20, a[i++]); |
82 | 90 | } |
83 | 91 | |
92 | @Test | |
84 | 93 | public void testRandom() { |
85 | 94 | int len = 100; |
86 | 95 | Random random = new Random(156); |
25 | 25 | |
26 | 26 | import java.text.MessageFormat; |
27 | 27 | |
28 | import junit.framework.TestCase; | |
29 | 28 | import org.junit.Ignore; |
29 | import org.junit.Test; | |
30 | 30 | |
31 | 31 | @Ignore |
32 | public class MessageFormatterPerfTest extends TestCase { | |
32 | public class MessageFormatterPerfTest{ //extends TestCase { | |
33 | 33 | |
34 | 34 | Integer i1 = new Integer(1); |
35 | 35 | Integer i2 = new Integer(2); |
37 | 37 | // |
38 | 38 | static long REFERENCE_BIPS = 48416; |
39 | 39 | |
40 | public MessageFormatterPerfTest(String name) { | |
41 | super(name); | |
42 | } | |
43 | ||
44 | protected void setUp() throws Exception { | |
45 | } | |
46 | ||
47 | protected void tearDown() throws Exception { | |
48 | } | |
49 | ||
50 | 40 | public void XtestJDKFormatterPerf() { |
51 | 41 | jdkMessageFormatter(RUN_LENGTH); |
52 | 42 | double duration = jdkMessageFormatter(RUN_LENGTH); |
53 | 43 | System.out.println("jdk duration = " + duration + " nanos"); |
54 | 44 | } |
55 | 45 | |
46 | @Test | |
56 | 47 | public void testSLF4JPerf_OneArg() { |
57 | 48 | slf4jMessageFormatter_OneArg(RUN_LENGTH); |
58 | 49 | double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH); |
61 | 52 | BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS); |
62 | 53 | } |
63 | 54 | |
55 | @Test | |
64 | 56 | public void testSLF4JPerf_TwoArg() { |
65 | 57 | slf4jMessageFormatter_TwoArg(RUN_LENGTH); |
66 | 58 | double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH); |
23 | 23 | */ |
24 | 24 | package org.slf4j.helpers; |
25 | 25 | |
26 | import static org.junit.Assert.assertTrue; | |
27 | import static org.junit.Assert.fail; | |
28 | ||
26 | 29 | import java.lang.reflect.InvocationHandler; |
27 | 30 | import java.lang.reflect.InvocationTargetException; |
28 | 31 | import java.lang.reflect.Method; |
33 | 36 | import java.util.List; |
34 | 37 | import java.util.Set; |
35 | 38 | |
36 | import junit.framework.TestCase; | |
39 | import org.junit.Test; | |
37 | 40 | import org.slf4j.Logger; |
38 | 41 | |
39 | 42 | /** |
40 | 43 | * @author Chetan Mehrotra |
41 | 44 | */ |
42 | public class SubstitutableLoggerTest extends TestCase { | |
45 | public class SubstitutableLoggerTest { | |
43 | 46 | private static final Set<String> EXCLUDED_METHODS = new HashSet<String>(Arrays.asList("getName")); |
44 | 47 | |
48 | @Test | |
45 | 49 | public void testDelegate() throws Exception { |
46 | 50 | SubstituteLogger log = new SubstituteLogger("foo"); |
47 | 51 | assertTrue(log.delegate() instanceof NOPLogger); |
23 | 23 | */ |
24 | 24 | package org.slf4j.helpers; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertNotNull; | |
28 | import static org.junit.Assert.assertTrue; | |
29 | ||
30 | import org.junit.Test; | |
27 | 31 | import org.slf4j.Logger; |
28 | 32 | |
29 | 33 | import java.util.Arrays; |
30 | 34 | import java.util.HashSet; |
31 | 35 | import java.util.Set; |
32 | 36 | |
33 | public class SubstituteLoggerFactoryTest extends TestCase { | |
37 | public class SubstituteLoggerFactoryTest { | |
34 | 38 | private SubstituteLoggerFactory factory = new SubstituteLoggerFactory(); |
35 | 39 | |
40 | @Test | |
36 | 41 | public void testFactory() { |
37 | 42 | Logger log = factory.getLogger("foo"); |
38 | 43 | assertNotNull(log); |
41 | 46 | assertTrue("Loggers with same name must be same", log == log2); |
42 | 47 | } |
43 | 48 | |
49 | @Test | |
44 | 50 | public void testLoggerNameList() { |
45 | 51 | factory.getLogger("foo1"); |
46 | 52 | factory.getLogger("foo2"); |
51 | 57 | assertEquals(expectedNames, actualNames); |
52 | 58 | } |
53 | 59 | |
60 | @Test | |
54 | 61 | public void testLoggers() { |
55 | 62 | factory.getLogger("foo1"); |
56 | 63 | factory.getLogger("foo2"); |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
1 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
3 | 3 | |
4 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 6 | <parent> |
7 | 7 | <groupId>org.slf4j</groupId> |
8 | 8 | <artifactId>slf4j-parent</artifactId> |
9 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
10 | 10 | </parent> |
11 | 11 | |
12 | 12 | <artifactId>slf4j-ext</artifactId> |
47 | 47 | </dependencies> |
48 | 48 | |
49 | 49 | <build> |
50 | <plugins> | |
51 | <plugin> | |
52 | <groupId>org.apache.maven.plugins</groupId> | |
53 | <artifactId>maven-compiler-plugin</artifactId> | |
54 | <configuration> | |
55 | <source>${required.jdk.version}</source> | |
56 | <target>${required.jdk.version}</target> | |
57 | </configuration> | |
58 | </plugin> | |
59 | ||
50 | <plugins> | |
60 | 51 | <plugin> |
61 | 52 | <groupId>org.apache.maven.plugins</groupId> |
62 | 53 | <artifactId>maven-surefire-plugin</artifactId> |
63 | 54 | <configuration> |
64 | <!-- http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html --> | |
55 | <!-- http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html --> | |
65 | 56 | <printSummary>false</printSummary> |
66 | 57 | <forkMode>once</forkMode> |
67 | 58 | <reportFormat>plain</reportFormat> |
73 | 64 | </configuration> |
74 | 65 | </plugin> |
75 | 66 | |
76 | ||
77 | 67 | <plugin> |
78 | 68 | <groupId>org.apache.maven.plugins</groupId> |
79 | 69 | <artifactId>maven-jar-plugin</artifactId> |
80 | 70 | <configuration> |
81 | 71 | <archive> |
82 | 72 | <manifestEntries> |
83 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
84 | <Bundle-Description>${project.description}</Bundle-Description> | |
85 | <Implementation-Version>${project.version}</Implementation-Version> | |
86 | 73 | <Premain-Class>org.slf4j.agent.AgentPremain</Premain-Class> |
87 | 74 | <!-- what is the proper way to specify the maven full name? /ravn --> |
88 | 75 | <Boot-Class-Path>../../../../javassist/javassist/3.4.GA/javassist-3.4.GA.jar javassist-3.4.GA.jar javassist.jar</Boot-Class-Path> |
89 | 76 | </manifestEntries> |
90 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
91 | 77 | </archive> |
92 | </configuration> | |
93 | </plugin> | |
78 | </configuration> | |
79 | </plugin> | |
94 | 80 | </plugins> |
95 | 81 | |
96 | 82 | </build> |
97 | 83 | |
98 | <reporting> | |
99 | <plugins> | |
100 | ||
101 | </plugins> | |
102 | </reporting> | |
103 | ||
104 | 84 | </project>⏎ |
101 | 101 | public XLogger(Logger logger) { |
102 | 102 | // If class B extends A, assuming B does not override method x(), the caller |
103 | 103 | // of new B().x() is A and not B, see also |
104 | // http://bugzilla.slf4j.org/show_bug.cgi?id=114 | |
104 | // http://jira.qos.ch/browse/SLF4J-105 | |
105 | 105 | super(logger, LoggerWrapper.class.getName()); |
106 | 106 | } |
107 | 107 |
91 | 91 | */ |
92 | 92 | public static String getSignature(CtBehavior method) throws NotFoundException { |
93 | 93 | |
94 | CtClass parameterTypes[] = method.getParameterTypes(); | |
94 | CtClass[] parameterTypes = method.getParameterTypes(); | |
95 | 95 | |
96 | 96 | CodeAttribute codeAttribute = method.getMethodInfo().getCodeAttribute(); |
97 | 97 |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | public class NDCTest extends TestCase { | |
28 | import org.junit.Before; | |
29 | import org.junit.Test; | |
29 | 30 | |
30 | protected void setUp() throws Exception { | |
31 | super.setUp(); | |
31 | public class NDCTest { | |
32 | ||
33 | @Before | |
34 | public void setUp() throws Exception { | |
32 | 35 | MDC.clear(); |
33 | 36 | } |
34 | 37 | |
35 | protected void tearDown() throws Exception { | |
36 | super.tearDown(); | |
37 | } | |
38 | ||
38 | @Test | |
39 | 39 | public void testEmpty() { |
40 | 40 | assertEquals("", NDC.pop()); |
41 | 41 | } |
42 | 42 | |
43 | ||
44 | @Test | |
43 | 45 | public void testSmoke() { |
44 | 46 | NDC.push("a"); |
45 | 47 | String result = NDC.pop(); |
46 | 48 | assertEquals("a", result); |
47 | 49 | } |
48 | 50 | |
51 | ||
52 | @Test | |
49 | 53 | public void testSmoke2() { |
50 | 54 | NDC.push("a"); |
51 | 55 | NDC.push("b"); |
23 | 23 | */ |
24 | 24 | package org.slf4j.cal10n_dummy; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
26 | 28 | import java.util.Locale; |
27 | 29 | |
28 | import junit.framework.TestCase; | |
29 | ||
30 | 30 | import org.apache.log4j.spi.LoggingEvent; |
31 | import org.junit.Before; | |
32 | import org.junit.Test; | |
31 | 33 | import org.slf4j.cal10n.LocLogger; |
32 | 34 | import org.slf4j.cal10n.LocLoggerFactory; |
33 | 35 | import org.slf4j.dummyExt.ListAppender; |
34 | 36 | |
35 | 37 | import ch.qos.cal10n.IMessageConveyor; |
36 | 38 | import ch.qos.cal10n.MessageConveyor; |
37 | ||
38 | public class LocLoggerTest extends TestCase { | |
39 | public class LocLoggerTest { | |
39 | 40 | |
40 | 41 | ListAppender listAppender; |
41 | 42 | org.apache.log4j.Logger log4jRoot; |
45 | 46 | |
46 | 47 | final static String EXPECTED_FILE_NAME = "LocLoggerTest.java"; |
47 | 48 | |
48 | public LocLoggerTest(String name) { | |
49 | super(name); | |
50 | } | |
51 | 49 | |
50 | @Before | |
52 | 51 | public void setUp() throws Exception { |
53 | super.setUp(); | |
54 | ||
55 | 52 | // start from a clean slate for each test |
56 | 53 | |
57 | 54 | listAppender = new ListAppender(); |
66 | 63 | assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName()); |
67 | 64 | } |
68 | 65 | |
69 | public void tearDown() throws Exception { | |
70 | super.tearDown(); | |
71 | } | |
72 | 66 | |
67 | @Test | |
73 | 68 | public void testSmoke() { |
74 | 69 | LocLogger locLogger = llFactory_uk.getLocLogger(this.getClass()); |
75 | 70 | locLogger.info(Months.JAN); |
23 | 23 | */ |
24 | 24 | package org.slf4j.cal10n_dummy; |
25 | 25 | |
26 | import junit.framework.*; | |
26 | import org.junit.runner.RunWith; | |
27 | import org.junit.runners.Suite; | |
28 | import org.junit.runners.Suite.SuiteClasses; | |
27 | 29 | |
28 | public class PackageTest extends TestCase { | |
29 | ||
30 | public static Test suite() { | |
31 | TestSuite suite = new TestSuite(); | |
32 | suite.addTestSuite(LocLoggerTest.class); | |
33 | return suite; | |
34 | } | |
30 | @RunWith(Suite.class) | |
31 | @SuiteClasses({ LocLoggerTest.class }) | |
32 | public class PackageTest { | |
35 | 33 | } |
23 | 23 | */ |
24 | 24 | package org.slf4j.dummyExt; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | ||
26 | 28 | import java.util.Date; |
27 | 29 | import java.util.Locale; |
28 | 30 | import java.util.TimeZone; |
29 | 31 | |
30 | import junit.framework.TestCase; | |
31 | ||
32 | 32 | import org.apache.log4j.spi.LocationInfo; |
33 | 33 | import org.apache.log4j.spi.LoggingEvent; |
34 | import org.junit.After; | |
35 | import org.junit.Before; | |
36 | import org.junit.Test; | |
34 | 37 | import org.slf4j.MDC; |
35 | 38 | import org.slf4j.ext.EventData; |
36 | 39 | import org.slf4j.ext.EventLogger; |
37 | ||
38 | public class EventLoggerTest extends TestCase { | |
40 | public class EventLoggerTest { | |
39 | 41 | |
40 | 42 | ListAppender listAppender; |
41 | 43 | org.apache.log4j.Logger log4; |
42 | 44 | |
43 | 45 | final static String EXPECTED_FILE_NAME = "EventLoggerTest.java"; |
44 | 46 | |
45 | public EventLoggerTest(String name) { | |
46 | super(name); | |
47 | } | |
48 | 47 | |
48 | @Before | |
49 | 49 | public void setUp() throws Exception { |
50 | super.setUp(); | |
51 | 50 | |
52 | 51 | // start from a clean slate for each test |
53 | 52 | |
67 | 66 | |
68 | 67 | } |
69 | 68 | |
69 | @After | |
70 | 70 | public void tearDown() throws Exception { |
71 | super.tearDown(); | |
72 | 71 | MDC.clear(); |
73 | 72 | } |
74 | 73 | |
76 | 75 | assertEquals(expectedMsg, le.getMessage()); |
77 | 76 | assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName()); |
78 | 77 | } |
79 | ||
78 | ||
79 | @Test | |
80 | 80 | public void testEventLogger() { |
81 | 81 | EventData data[] = new EventData[2]; |
82 | 82 | data[0] = new EventData(); |
23 | 23 | */ |
24 | 24 | package org.slf4j.dummyExt; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | import org.junit.Test; | |
28 | 29 | import org.slf4j.MDC; |
29 | 30 | import org.slf4j.ext.MDCStrLookup; |
31 | public class MDCStrLookupTest { | |
30 | 32 | |
31 | public class MDCStrLookupTest extends TestCase { | |
32 | ||
33 | public MDCStrLookupTest(String name) { | |
34 | super(name); | |
35 | } | |
36 | ||
37 | public void setUp() throws Exception { | |
38 | super.setUp(); | |
39 | } | |
40 | ||
41 | public void tearDown() throws Exception { | |
42 | super.tearDown(); | |
43 | } | |
44 | ||
33 | @Test | |
45 | 34 | public void testLookup() throws Exception { |
46 | 35 | MDC.put("key", "value"); |
47 | 36 | MDC.put("number", "2"); |
25 | 25 | |
26 | 26 | import junit.framework.*; |
27 | 27 | |
28 | public class PackageTest extends TestCase { | |
28 | import org.junit.runner.RunWith; | |
29 | import org.junit.runners.Suite; | |
30 | import org.junit.runners.Suite.SuiteClasses; | |
29 | 31 | |
30 | public static Test suite() { | |
31 | TestSuite suite = new TestSuite(); | |
32 | suite.addTestSuite(MDCStrLookupTest.class); | |
33 | suite.addTestSuite(XLoggerTest.class); | |
34 | suite.addTestSuite(EventLoggerTest.class); | |
35 | return suite; | |
36 | } | |
32 | @RunWith(Suite.class) | |
33 | @SuiteClasses({ MDCStrLookupTest.class, XLoggerTest.class, EventLoggerTest.class }) | |
34 | public class PackageTest { | |
37 | 35 | } |
23 | 23 | */ |
24 | 24 | package org.slf4j.dummyExt; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | 28 | import org.apache.log4j.spi.LocationInfo; |
29 | 29 | import org.apache.log4j.spi.LoggingEvent; |
30 | import org.junit.Before; | |
31 | import org.junit.Test; | |
30 | 32 | import org.slf4j.ext.XLogger; |
31 | 33 | import org.slf4j.ext.XLoggerFactory; |
32 | 34 | |
33 | public class XLoggerTest extends TestCase { | |
35 | public class XLoggerTest { | |
34 | 36 | |
35 | 37 | ListAppender listAppender; |
36 | 38 | org.apache.log4j.Logger log4jRoot; |
37 | 39 | |
38 | 40 | final static String EXPECTED_FILE_NAME = "XLoggerTest.java"; |
39 | 41 | |
40 | public XLoggerTest(String name) { | |
41 | super(name); | |
42 | } | |
43 | ||
42 | @Before | |
44 | 43 | public void setUp() throws Exception { |
45 | super.setUp(); | |
46 | 44 | |
47 | 45 | // start from a clean slate for each test |
48 | 46 | |
51 | 49 | log4jRoot = org.apache.log4j.Logger.getRootLogger(); |
52 | 50 | log4jRoot.addAppender(listAppender); |
53 | 51 | log4jRoot.setLevel(org.apache.log4j.Level.TRACE); |
54 | } | |
55 | ||
56 | public void tearDown() throws Exception { | |
57 | super.tearDown(); | |
58 | 52 | } |
59 | 53 | |
60 | 54 | void verify(LoggingEvent le, String expectedMsg) { |
73 | 67 | assertEquals(le.getLevel().toString(), level.toString()); |
74 | 68 | } |
75 | 69 | |
70 | @Test | |
76 | 71 | public void testEntering() { |
77 | 72 | XLogger logger = XLoggerFactory.getXLogger("UnitTest"); |
78 | 73 | logger.entry(); |
88 | 83 | verify((LoggingEvent) listAppender.list.get(2), "entry with (test)"); |
89 | 84 | } |
90 | 85 | |
86 | @Test | |
91 | 87 | public void testExiting() { |
92 | 88 | XLogger logger = XLoggerFactory.getXLogger("UnitTest"); |
93 | 89 | logger.exit(); |
100 | 96 | verify((LoggingEvent) listAppender.list.get(2), "exit with (false)"); |
101 | 97 | } |
102 | 98 | |
99 | @Test | |
103 | 100 | public void testThrowing() { |
104 | 101 | XLogger logger = XLoggerFactory.getXLogger("UnitTest"); |
105 | 102 | Throwable t = new UnsupportedOperationException("Test"); |
111 | 108 | verifyWithLevelAndException(event, XLogger.Level.DEBUG, "throwing", t); |
112 | 109 | } |
113 | 110 | |
111 | @Test | |
114 | 112 | public void testCaught() { |
115 | 113 | XLogger logger = XLoggerFactory.getXLogger("UnitTest"); |
116 | 114 | long x = 5; |
127 | 125 | verifyWithLevelAndException((LoggingEvent) listAppender.list.get(1), XLogger.Level.DEBUG, "catching", t); |
128 | 126 | } |
129 | 127 | |
130 | // See http://bugzilla.slf4j.org/show_bug.cgi?id=114 | |
128 | // See http://jira.qos.ch/browse/SLF4J-105 | |
129 | // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=114 | |
130 | @Test | |
131 | 131 | public void testLocationExtraction_Bug114() { |
132 | 132 | XLogger logger = XLoggerFactory.getXLogger("UnitTest"); |
133 | 133 | int line = 135; // requires update if line numbers change |
23 | 23 | */ |
24 | 24 | package org.slf4j.instrumentation; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | public class ToStringHelperTest extends TestCase { | |
28 | import org.junit.Test; | |
29 | 29 | |
30 | public class ToStringHelperTest { | |
31 | ||
32 | @Test | |
30 | 33 | public void testRenderer() { |
31 | 34 | assertEquals("", "null", ToStringHelper.render(null)); |
32 | 35 | assertEquals("", "a", ToStringHelper.render("a")); |
23 | 23 | */ |
24 | 24 | package org.slf4j.profiler; |
25 | 25 | |
26 | import junit.framework.*; | |
26 | import org.junit.runner.RunWith; | |
27 | import org.junit.runners.Suite; | |
28 | import org.junit.runners.Suite.SuiteClasses; | |
27 | 29 | |
28 | public class PackageTest extends TestCase { | |
30 | @RunWith(Suite.class) | |
31 | @SuiteClasses({UtilTest.class, | |
32 | ProfilerTest.class}) | |
33 | public class PackageTest { | |
29 | 34 | |
30 | public static Test suite() { | |
31 | TestSuite suite = new TestSuite(); | |
32 | suite.addTestSuite(UtilTest.class); | |
33 | suite.addTestSuite(ProfilerTest.class); | |
34 | return suite; | |
35 | } | |
35 | ||
36 | 36 | }⏎ |
23 | 23 | */ |
24 | 24 | package org.slf4j.profiler; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertNotNull; | |
28 | import static org.junit.Assert.assertNull; | |
27 | 29 | |
30 | import org.junit.Test; | |
28 | 31 | import org.slf4j.Logger; |
29 | 32 | import org.slf4j.LoggerFactory; |
30 | ||
31 | public class ProfilerTest extends TestCase { | |
33 | public class ProfilerTest { | |
32 | 34 | |
33 | 35 | Logger logger = LoggerFactory.getLogger(ProfilerTest.class); |
34 | 36 | |
35 | public void setUp() throws Exception { | |
36 | super.setUp(); | |
37 | } | |
38 | ||
37 | @Test | |
39 | 38 | public void testSmoke() { |
40 | 39 | Profiler profiler = new Profiler("SMOKE"); |
41 | 40 | profiler.stop(); |
48 | 47 | assertNull(profiler.getLastTimeInstrument()); |
49 | 48 | } |
50 | 49 | |
50 | @Test | |
51 | 51 | public void testBasicProfiling() { |
52 | 52 | Profiler profiler = new Profiler("BAS"); |
53 | 53 | |
79 | 79 | // |-- Total elapsed time [subtask] 7.321 milliseconds. |
80 | 80 | // |-- elapsed time [doZ] 3.211 milliseconds. |
81 | 81 | // |-- Total elapsed time [BAS] 30.317 milliseconds. |
82 | @Test | |
82 | 83 | public void testNestedProfiling() { |
83 | 84 | |
84 | 85 | Profiler profiler = new Profiler("BAS"); |
23 | 23 | */ |
24 | 24 | package org.slf4j.profiler; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | public class UtilTest extends TestCase { | |
28 | import org.junit.Test; | |
29 | 29 | |
30 | public UtilTest(String name) { | |
31 | super(name); | |
32 | } | |
30 | public class UtilTest { | |
33 | 31 | |
34 | protected void setUp() throws Exception { | |
35 | super.setUp(); | |
36 | } | |
37 | ||
38 | protected void tearDown() throws Exception { | |
39 | super.tearDown(); | |
40 | } | |
41 | ||
32 | @Test | |
42 | 33 | public void testSelectDurationUnitForDisplay() throws InterruptedException { |
43 | 34 | assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10)); |
44 | 35 | assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9 * Util.NANOS_IN_ONE_MICROSECOND)); |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
0 | 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
1 | 2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
2 | 3 | |
5 | 6 | <parent> |
6 | 7 | <groupId>org.slf4j</groupId> |
7 | 8 | <artifactId>slf4j-parent</artifactId> |
8 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
9 | 10 | </parent> |
10 | 11 | |
11 | 12 | <artifactId>slf4j-jcl</artifactId> |
20 | 21 | <groupId>org.slf4j</groupId> |
21 | 22 | <artifactId>slf4j-api</artifactId> |
22 | 23 | </dependency> |
23 | ||
24 | 24 | <dependency> |
25 | 25 | <groupId>commons-logging</groupId> |
26 | 26 | <artifactId>commons-logging</artifactId> |
27 | 27 | <version>1.1.1</version> |
28 | 28 | </dependency> |
29 | ||
30 | 29 | </dependencies> |
31 | 30 | |
32 | <build> | |
33 | <plugins> | |
34 | <plugin> | |
35 | <groupId>org.apache.maven.plugins</groupId> | |
36 | <artifactId>maven-jar-plugin</artifactId> | |
37 | <configuration> | |
38 | <archive> | |
39 | <manifestEntries> | |
40 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
41 | <Bundle-Description>${project.description}</Bundle-Description> | |
42 | <Implementation-Version>${project.version}</Implementation-Version> | |
43 | </manifestEntries> | |
44 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
45 | </archive> | |
46 | </configuration> | |
47 | </plugin> | |
48 | ||
49 | </plugins> | |
50 | </build> | |
51 | ||
52 | 31 | </project>⏎ |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import static org.junit.Assert.assertNull; | |
27 | ||
26 | 28 | import java.util.logging.Level; |
27 | 29 | |
28 | import junit.framework.TestCase; | |
30 | import org.junit.After; | |
31 | import org.junit.Before; | |
32 | import org.junit.Test; | |
29 | 33 | |
30 | 34 | /** |
31 | 35 | * Test whether invoking the SLF4J API causes problems or not. |
33 | 37 | * @author Ceki Gulcu |
34 | 38 | * |
35 | 39 | */ |
36 | public class InvocationTest extends TestCase { | |
40 | public class InvocationTest { | |
37 | 41 | |
38 | 42 | Level oldLevel; |
39 | 43 | java.util.logging.Logger root = java.util.logging.Logger.getLogger(""); |
40 | 44 | |
41 | public InvocationTest(String arg0) { | |
42 | super(arg0); | |
43 | } | |
44 | 45 | |
45 | protected void setUp() throws Exception { | |
46 | super.setUp(); | |
46 | @Before | |
47 | public void setUp() throws Exception { | |
47 | 48 | oldLevel = root.getLevel(); |
48 | 49 | root.setLevel(Level.OFF); |
49 | 50 | } |
50 | 51 | |
51 | protected void tearDown() throws Exception { | |
52 | super.tearDown(); | |
52 | @After | |
53 | public void tearDown() throws Exception { | |
53 | 54 | root.setLevel(oldLevel); |
54 | 55 | } |
55 | 56 | |
57 | @Test | |
56 | 58 | public void test1() { |
57 | 59 | Logger logger = LoggerFactory.getLogger("test1"); |
58 | 60 | logger.debug("Hello world."); |
59 | 61 | } |
60 | 62 | |
63 | @Test | |
61 | 64 | public void test2() { |
62 | 65 | Integer i1 = new Integer(1); |
63 | 66 | Integer i2 = new Integer(2); |
81 | 84 | logger.error("Hello world 4.", e); |
82 | 85 | } |
83 | 86 | |
87 | @Test | |
84 | 88 | public void testNull() { |
85 | 89 | Logger logger = LoggerFactory.getLogger("testNull"); |
86 | 90 | logger.debug(null); |
95 | 99 | logger.error(null, e); |
96 | 100 | } |
97 | 101 | |
102 | @Test | |
98 | 103 | public void testMarker() { |
99 | 104 | Logger logger = LoggerFactory.getLogger("testMarker"); |
100 | 105 | Marker blue = MarkerFactory.getMarker("BLUE"); |
114 | 119 | logger.error(blue, "hello {} and {} ", "world", "universe"); |
115 | 120 | } |
116 | 121 | |
122 | @Test | |
117 | 123 | public void testMDC() { |
118 | 124 | MDC.put("k", "v"); |
119 | 125 | assertNull(MDC.get("k")); |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | 11 | |
13 | 12 | <artifactId>slf4j-jdk14</artifactId> |
14 | ||
15 | 13 | <packaging>jar</packaging> |
16 | 14 | <name>SLF4J JDK14 Binding</name> |
17 | 15 | <description>SLF4J JDK14 Binding</description> |
18 | 16 | <url>http://www.slf4j.org</url> |
19 | ||
20 | 17 | |
21 | 18 | <dependencies> |
22 | 19 | <dependency> |
33 | 30 | </dependency> |
34 | 31 | </dependencies> |
35 | 32 | |
36 | <build> | |
37 | <plugins> | |
38 | <plugin> | |
39 | <groupId>org.apache.maven.plugins</groupId> | |
40 | <artifactId>maven-jar-plugin</artifactId> | |
41 | <configuration> | |
42 | <archive> | |
43 | <manifestEntries> | |
44 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
45 | <Bundle-Description>${project.description}</Bundle-Description> | |
46 | <Implementation-Version>${project.version}</Implementation-Version> | |
47 | </manifestEntries> | |
48 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
49 | </archive> | |
50 | </configuration> | |
51 | </plugin> | |
52 | </plugins> | |
53 | </build> | |
54 | ||
55 | 33 | </project>⏎ |
573 | 573 | LogRecord record = new LogRecord(level, msg); |
574 | 574 | record.setLoggerName(getName()); |
575 | 575 | record.setThrown(t); |
576 | // Note: parameters in record are not set because SLF4J only | |
577 | // supports a single formatting style | |
576 | 578 | fillCallerData(callerFQCN, record); |
577 | 579 | logger.log(record); |
578 | 580 | |
642 | 644 | // construction of location data for disabled log |
643 | 645 | // statements. As of 2008-07-31, callers of this method |
644 | 646 | // do not perform this check. See also |
645 | // http://bugzilla.slf4j.org/show_bug.cgi?id=90 | |
647 | // http://jira.qos.ch/browse/SLF4J-81 | |
646 | 648 | if (logger.isLoggable(julLevel)) { |
647 | 649 | log(callerFQCN, julLevel, message, t); |
648 | 650 | } |
23 | 23 | */ |
24 | 24 | package org.slf4j.impl; |
25 | 25 | |
26 | import static org.junit.Assert.assertNotNull; | |
27 | ||
26 | 28 | import java.util.logging.Handler; |
27 | 29 | import java.util.logging.LogRecord; |
28 | 30 | import java.util.logging.Logger; |
29 | 31 | |
30 | import junit.framework.TestCase; | |
32 | import org.junit.After; | |
33 | import org.junit.Before; | |
34 | import org.junit.Test; | |
31 | 35 | |
32 | public class JDK14AdapterLoggerNameTest extends TestCase { | |
36 | public class JDK14AdapterLoggerNameTest { | |
33 | 37 | private MockHandler mockHandler; |
34 | 38 | |
35 | protected void setUp() throws Exception { | |
36 | super.setUp(); | |
39 | @Before | |
40 | public void setUp() throws Exception { | |
37 | 41 | Logger logger = Logger.getLogger("TEST"); |
38 | 42 | mockHandler = new MockHandler(); |
39 | 43 | removeHandlers(logger); |
40 | 44 | logger.addHandler(mockHandler); |
41 | 45 | } |
42 | 46 | |
43 | protected void tearDown() throws Exception { | |
47 | @After | |
48 | public void tearDown() throws Exception { | |
44 | 49 | removeHandlers(Logger.getLogger("TEST")); |
45 | super.tearDown(); | |
46 | 50 | } |
47 | 51 | |
52 | @Test | |
48 | 53 | public void testLoggerNameusingJdkLogging() throws Exception { |
49 | 54 | Logger.getLogger("TEST").info("test message"); |
50 | 55 | assertCorrectLoggerName(); |
51 | 56 | |
52 | 57 | } |
53 | 58 | |
59 | @Test | |
54 | 60 | public void testLoggerNameUsingSlf4j() throws Exception { |
55 | 61 | JDK14LoggerFactory factory = new JDK14LoggerFactory(); |
56 | 62 | org.slf4j.Logger logger = factory.getLogger("TEST"); |
23 | 23 | */ |
24 | 24 | package org.slf4j.impl; |
25 | 25 | |
26 | import junit.framework.TestCase; | |
27 | ||
26 | import org.junit.Test; | |
28 | 27 | import org.slf4j.Logger; |
29 | 28 | import org.slf4j.LoggerFactory; |
30 | 29 | import org.slf4j.helpers.BogoPerf; |
31 | 30 | |
32 | public class PerfTest extends TestCase { | |
31 | public class PerfTest { | |
33 | 32 | |
34 | 33 | static long REFERENCE_BIPS = 9000; |
35 | 34 | |
36 | public PerfTest(String name) { | |
37 | super(name); | |
38 | } | |
39 | ||
40 | protected void setUp() throws Exception { | |
41 | super.setUp(); | |
42 | } | |
43 | ||
44 | protected void tearDown() throws Exception { | |
45 | super.tearDown(); | |
46 | } | |
47 | ||
35 | @Test | |
48 | 36 | public void testBug72() { |
49 | 37 | |
50 | 38 | int LEN = 1000 * 1000 * 10; |
33 | 33 | |
34 | 34 | import junit.framework.Assert; |
35 | 35 | |
36 | import junit.framework.TestCase; | |
36 | import org.junit.Test; | |
37 | 37 | import org.slf4j.Logger; |
38 | 38 | import org.slf4j.LoggerFactory; |
39 | 39 | |
40 | 40 | /** |
41 | * See http://bugzilla.slf4j.org/show_bug.cgi?id=261 | |
41 | * See http://jira.qos.ch/browse/SLF4J-252 | |
42 | 42 | * @author Thorbjorn Ravn Andersen |
43 | 43 | */ |
44 | public class LoggerSerializationTest extends TestCase { | |
44 | public class LoggerSerializationTest { | |
45 | 45 | |
46 | 46 | static class LoggerHolder implements Serializable { |
47 | 47 | private static final long serialVersionUID = 1L; |
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
60 | @Test | |
60 | 61 | public void testCanLoggerBeSerialized() throws IOException, ClassNotFoundException { |
61 | 62 | |
62 | 63 | LoggerHolder lh1 = new LoggerHolder(); |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | 11 | |
13 | 12 | <artifactId>slf4j-log4j12</artifactId> |
16 | 15 | <name>SLF4J LOG4J-12 Binding</name> |
17 | 16 | <description>SLF4J LOG4J-12 Binding</description> |
18 | 17 | <url>http://www.slf4j.org</url> |
19 | ||
20 | 18 | |
21 | 19 | <dependencies> |
22 | 20 | <dependency> |
30 | 28 | </dependency> |
31 | 29 | </dependencies> |
32 | 30 | |
33 | <build> | |
34 | <plugins> | |
35 | <plugin> | |
36 | <groupId>org.apache.maven.plugins</groupId> | |
37 | <artifactId>maven-jar-plugin</artifactId> | |
38 | <configuration> | |
39 | <archive> | |
40 | <manifestEntries> | |
41 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
42 | <Bundle-Description>${project.description}</Bundle-Description> | |
43 | <Implementation-Version>${project.version}</Implementation-Version> | |
44 | </manifestEntries> | |
45 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
46 | </archive> | |
47 | </configuration> | |
48 | </plugin> | |
49 | </plugins> | |
50 | </build> | |
51 | ||
52 | 31 | </project>⏎ |
47 | 47 | * The TRACE level was introduced in log4j version 1.2.12. In order to avoid |
48 | 48 | * crashing the host application, in the case the log4j version in use predates |
49 | 49 | * 1.2.12, the TRACE level will be mapped as DEBUG. See also <a |
50 | * href="http://bugzilla.slf4j.org/show_bug.cgi?id=68">bug 68</a>. | |
50 | * href="http://jira.qos.ch/browse/SLF4J-59">SLF4J-59</a>. | |
51 | 51 | * |
52 | 52 | * @author Ceki Gülcü |
53 | 53 | */ |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertNotNull; | |
28 | import static org.junit.Assert.assertNull; | |
29 | import static org.junit.Assert.fail; | |
30 | ||
26 | 31 | import java.util.HashMap; |
27 | 32 | import java.util.Map; |
28 | 33 | |
29 | 34 | import org.apache.log4j.spi.LoggingEvent; |
30 | ||
31 | import junit.framework.TestCase; | |
35 | import org.junit.After; | |
36 | import org.junit.Before; | |
37 | import org.junit.Test; | |
32 | 38 | |
33 | 39 | /** |
34 | 40 | * Test whether invoking the SLF4J API causes problems or not. |
36 | 42 | * @author Ceki Gulcu |
37 | 43 | * |
38 | 44 | */ |
39 | public class InvocationTest extends TestCase { | |
45 | public class InvocationTest { | |
40 | 46 | |
41 | 47 | ListAppender listAppender = new ListAppender(); |
42 | 48 | org.apache.log4j.Logger root; |
43 | 49 | |
44 | public InvocationTest(String arg0) { | |
45 | super(arg0); | |
50 | ||
51 | @Before | |
52 | public void setUp() throws Exception { | |
53 | root = org.apache.log4j.Logger.getRootLogger(); | |
54 | root.addAppender(listAppender); | |
46 | 55 | } |
47 | 56 | |
48 | protected void setUp() throws Exception { | |
49 | super.setUp(); | |
50 | root = org.apache.log4j.Logger.getRootLogger(); | |
51 | root.addAppender(listAppender); | |
52 | ||
53 | } | |
54 | ||
55 | protected void tearDown() throws Exception { | |
56 | super.tearDown(); | |
57 | @After | |
58 | public void tearDown() throws Exception { | |
57 | 59 | root.getLoggerRepository().resetConfiguration(); |
58 | 60 | } |
59 | ||
61 | ||
62 | @Test | |
60 | 63 | public void test1() { |
61 | 64 | Logger logger = LoggerFactory.getLogger("test1"); |
62 | 65 | logger.debug("Hello world."); |
63 | 66 | assertEquals(1, listAppender.list.size()); |
64 | 67 | } |
65 | 68 | |
69 | @Test | |
66 | 70 | public void test2() { |
67 | 71 | Integer i1 = new Integer(1); |
68 | 72 | Integer i2 = new Integer(2); |
89 | 93 | assertEquals(11, listAppender.list.size()); |
90 | 94 | } |
91 | 95 | |
96 | @Test | |
92 | 97 | public void testNull() { |
93 | 98 | Logger logger = LoggerFactory.getLogger("testNull"); |
94 | 99 | logger.trace(null); |
105 | 110 | assertEquals(8, listAppender.list.size()); |
106 | 111 | } |
107 | 112 | |
108 | // http://bugzilla.slf4j.org/show_bug.cgi?id=78 | |
113 | // http://jira.qos.ch/browse/SLF4J-69 | |
114 | // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=78 | |
115 | @Test | |
109 | 116 | public void testNullParameter_BUG78() { |
110 | 117 | Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78"); |
111 | 118 | String[] parameters = null; |
112 | 119 | String msg = "hello {}"; |
113 | 120 | |
114 | logger.debug(msg, parameters); | |
121 | logger.debug(msg, (Object[]) parameters); | |
122 | ||
115 | 123 | assertEquals(1, listAppender.list.size()); |
116 | 124 | LoggingEvent e = (LoggingEvent) listAppender.list.get(0); |
117 | 125 | assertEquals(msg, e.getMessage()); |
118 | 126 | } |
119 | 127 | |
128 | @Test | |
120 | 129 | public void testMarker() { |
121 | 130 | Logger logger = LoggerFactory.getLogger("testMarker"); |
122 | 131 | Marker blue = MarkerFactory.getMarker("BLUE"); |
138 | 147 | assertEquals(12, listAppender.list.size()); |
139 | 148 | } |
140 | 149 | |
150 | @Test | |
141 | 151 | public void testMDC() { |
142 | 152 | MDC.put("k", "v"); |
143 | 153 | assertNotNull(MDC.get("k")); |
158 | 168 | } |
159 | 169 | } |
160 | 170 | |
171 | @Test | |
161 | 172 | public void testMDCContextMapValues() { |
162 | 173 | Map<String, String> map = new HashMap<String, String>(); |
163 | 174 | map.put("ka", "va"); |
25 | 25 | |
26 | 26 | import java.util.Random; |
27 | 27 | |
28 | import junit.framework.TestCase; | |
29 | ||
28 | import org.junit.After; | |
29 | import org.junit.Before; | |
30 | import org.junit.Test; | |
30 | 31 | import org.slf4j.Logger; |
31 | 32 | import org.slf4j.LoggerFactory; |
32 | ||
33 | public class RecursiveInitializationTest extends TestCase { | |
33 | public class RecursiveInitializationTest { | |
34 | 34 | |
35 | 35 | // value of LogManager.DEFAULT_CONFIGURATION_KEY; |
36 | 36 | static String CONFIG_FILE_KEY = "log4j.configuration"; |
37 | 37 | |
38 | 38 | int diff = new Random().nextInt(10000); |
39 | 39 | |
40 | protected void setUp() throws Exception { | |
40 | @Before | |
41 | public void setUp() throws Exception { | |
41 | 42 | System.setProperty(CONFIG_FILE_KEY, "recursiveInit.properties"); |
42 | super.setUp(); | |
43 | 43 | } |
44 | 44 | |
45 | protected void tearDown() throws Exception { | |
45 | @After | |
46 | public void tearDown() throws Exception { | |
46 | 47 | System.clearProperty(CONFIG_FILE_KEY); |
47 | super.tearDown(); | |
48 | 48 | } |
49 | 49 | |
50 | @Test | |
50 | 51 | public void testLog4j() { |
51 | 52 | Logger logger = LoggerFactory.getLogger("x" + diff); |
52 | 53 | System.out.println("logger class=" + logger.getClass().getName()); |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | 11 | |
13 | 12 | <artifactId>slf4j-migrator</artifactId> |
16 | 15 | <name>SLF4J Migrator</name> |
17 | 16 | <description>SLF4J Migrator</description> |
18 | 17 | |
19 | ||
20 | <build> | |
21 | <plugins> | |
22 | <plugin> | |
23 | <groupId>org.apache.maven.plugins</groupId> | |
24 | <artifactId>maven-compiler-plugin</artifactId> | |
25 | <configuration> | |
26 | <source>${required.jdk.version}</source> | |
27 | <target>${required.jdk.version}</target> | |
28 | </configuration> | |
29 | </plugin> | |
30 | ||
31 | <plugin> | |
32 | <groupId>org.apache.maven.plugins</groupId> | |
33 | <artifactId>maven-jar-plugin</artifactId> | |
34 | <configuration> | |
35 | <archive> | |
36 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
37 | </archive> | |
38 | </configuration> | |
39 | </plugin> | |
40 | ||
41 | </plugins> | |
42 | ||
43 | </build> | |
44 | ||
45 | 18 | </project>⏎ |
47 | 47 | return filename; |
48 | 48 | } |
49 | 49 | StringBuilder buf = new StringBuilder(desiredLength); |
50 | buf.append(filename.substring(0, firstIndex + 1)); | |
50 | buf.append(filename, 0, firstIndex + 1); | |
51 | 51 | buf.append(FILLER); |
52 | 52 | int nextIndex = computeNextIndex(filename, firstIndex); |
53 | 53 | if (nextIndex != -1) { |
26 | 26 | import java.io.File; |
27 | 27 | import java.io.IOException; |
28 | 28 | |
29 | import junit.framework.TestCase; | |
30 | ||
31 | import org.slf4j.migrator.InplaceFileConverter; | |
29 | import org.junit.Ignore; | |
30 | import org.junit.Test; | |
32 | 31 | import org.slf4j.migrator.internal.NopProgressListener; |
33 | 32 | import org.slf4j.migrator.line.EmptyRuleSet; |
33 | public class FileConverterTest { | |
34 | 34 | |
35 | public class FileConverterTest extends TestCase { | |
36 | 35 | |
37 | public FileConverterTest(String arg0) { | |
38 | super(arg0); | |
39 | } | |
40 | ||
41 | protected void setUp() throws Exception { | |
42 | super.setUp(); | |
43 | } | |
44 | ||
45 | protected void tearDown() throws Exception { | |
46 | super.tearDown(); | |
47 | } | |
48 | ||
49 | public void test() { | |
50 | } | |
51 | ||
36 | @Test | |
37 | @Ignore | |
52 | 38 | public void XtestNOP() throws IOException { |
53 | 39 | InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet(), new NopProgressListener()); |
54 | 40 | fc.convert(new File("c:/varargs.txt")); |
25 | 25 | |
26 | 26 | import java.io.File; |
27 | 27 | |
28 | import org.slf4j.migrator.Constant; | |
29 | import org.slf4j.migrator.ProjectConverter; | |
28 | import org.junit.Ignore; | |
29 | import org.junit.Test; | |
30 | 30 | import org.slf4j.migrator.internal.NopProgressListener; |
31 | 31 | |
32 | import junit.framework.TestCase; | |
33 | ||
34 | public class ProjectConverterTest extends TestCase { | |
32 | public class ProjectConverterTest { | |
35 | 33 | |
36 | 34 | public void test() { |
37 | 35 | } |
38 | 36 | |
37 | @Test | |
38 | @Ignore | |
39 | 39 | public void XtestBarracuda() { |
40 | 40 | ProjectConverter pc = new ProjectConverter(Constant.LOG4J_TO_SLF4J, new NopProgressListener()); |
41 | 41 | File projectFolder = new File("c:/home/ceki//Varia/Barracuda"); |
23 | 23 | */ |
24 | 24 | package org.slf4j.migrator.helper; |
25 | 25 | |
26 | import org.slf4j.migrator.helper.Abbreviator; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | import static org.junit.Assert.assertTrue; | |
27 | 28 | |
28 | import junit.framework.TestCase; | |
29 | ||
30 | public class AbbreviatorTest extends TestCase { | |
29 | import org.junit.Test; | |
30 | public class AbbreviatorTest { | |
31 | 31 | |
32 | 32 | static final char FS = '/'; |
33 | 33 | static final String INPUT_0 = "/abc/123456/ABC"; |
35 | 35 | |
36 | 36 | RandomHelper rh = new RandomHelper(FS); |
37 | 37 | |
38 | public AbbreviatorTest(String arg0) { | |
39 | super(arg0); | |
40 | } | |
41 | ||
42 | protected void setUp() throws Exception { | |
43 | super.setUp(); | |
44 | } | |
45 | ||
46 | protected void tearDown() throws Exception { | |
47 | super.tearDown(); | |
48 | } | |
49 | ||
38 | @Test | |
50 | 39 | public void testSmoke() { |
51 | 40 | { |
52 | 41 | Abbreviator abb = new Abbreviator(2, 100, FS); |
66 | 55 | } |
67 | 56 | } |
68 | 57 | |
58 | @Test | |
69 | 59 | public void testImpossibleToAbbreviate() { |
70 | 60 | Abbreviator abb = new Abbreviator(2, 20, FS); |
71 | 61 | String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth"; |
73 | 63 | assertEquals(in, r); |
74 | 64 | } |
75 | 65 | |
66 | @Test | |
76 | 67 | public void testNoFS() { |
77 | 68 | Abbreviator abb = new Abbreviator(2, 100, FS); |
78 | 69 | String r = abb.abbreviate("hello"); |
80 | 71 | |
81 | 72 | } |
82 | 73 | |
74 | @Test | |
83 | 75 | public void testZeroPrefix() { |
84 | 76 | { |
85 | 77 | Abbreviator abb = new Abbreviator(0, 100, FS); |
88 | 80 | } |
89 | 81 | } |
90 | 82 | |
83 | @Test | |
91 | 84 | public void testTheories() { |
92 | 85 | int MAX_RANDOM_FIXED_LEN = 20; |
93 | 86 | int MAX_RANDOM_AVG_LEN = 20; |
23 | 23 | */ |
24 | 24 | package org.slf4j.migrator.line; |
25 | 25 | |
26 | import org.slf4j.migrator.line.JCLRuleSet; | |
27 | import org.slf4j.migrator.line.LineConverter; | |
26 | import static org.junit.Assert.assertEquals; | |
28 | 27 | |
29 | import junit.framework.TestCase; | |
30 | ||
31 | public class JCLRuleSetTest extends TestCase { | |
28 | import org.junit.Test; | |
29 | public class JCLRuleSetTest { | |
32 | 30 | |
33 | 31 | LineConverter jclConverter = new LineConverter(new JCLRuleSet()); |
34 | 32 | |
33 | @Test | |
35 | 34 | public void testImportReplacement() { |
36 | 35 | // LogFactory import replacement |
37 | 36 | assertEquals("import org.slf4j.LoggerFactory;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.LogFactory;")); |
39 | 38 | assertEquals("import org.slf4j.Logger;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.Log;")); |
40 | 39 | } |
41 | 40 | |
41 | ||
42 | @Test | |
42 | 43 | public void testLogFactoryGetLogReplacement() { |
43 | 44 | // Logger declaration and instanciation without modifier |
44 | 45 | assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);", |
64 | 65 | jclConverter.getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation")); |
65 | 66 | } |
66 | 67 | |
68 | @Test | |
67 | 69 | public void testLogFactoryGetFactoryReplacement() { |
68 | 70 | |
69 | 71 | // Logger declaration and instanciation without modifier |
90 | 92 | jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation")); |
91 | 93 | } |
92 | 94 | |
95 | ||
96 | @Test | |
93 | 97 | public void testLogDeclarationReplacement() { |
94 | 98 | |
95 | 99 | // simple Logger declaration |
105 | 109 | assertEquals("//private Logger myLog;", jclConverter.getOneLineReplacement("//private Log myLog;")); |
106 | 110 | } |
107 | 111 | |
112 | @Test | |
108 | 113 | public void testMultiLineReplacement() { |
109 | 114 | // Logger declaration on a line |
110 | 115 | assertEquals("protected Logger log =", jclConverter.getOneLineReplacement("protected Log log =")); |
23 | 23 | */ |
24 | 24 | package org.slf4j.migrator.line; |
25 | 25 | |
26 | import org.slf4j.migrator.line.JCLRuleSet; | |
27 | import org.slf4j.migrator.line.LineConverter; | |
28 | import org.slf4j.migrator.line.Log4jRuleSet; | |
26 | import static org.junit.Assert.assertEquals; | |
29 | 27 | |
30 | import junit.framework.TestCase; | |
31 | ||
32 | public class NoConversionTest extends TestCase { | |
28 | import org.junit.Test; | |
29 | public class NoConversionTest { | |
33 | 30 | |
34 | 31 | /** |
35 | 32 | * This test shows that performing JCL to SLF4J conversion has no impact on |
36 | 33 | * Log4j implementation |
37 | 34 | */ |
35 | @Test | |
38 | 36 | public void testJclOverLog4jConversion() { |
39 | 37 | // running jcl to slf4j conversion |
40 | 38 | // JCLMatcher jclMatcher = |
55 | 53 | * This test shows that performing Log4j to SLF4J conversion has no impact on |
56 | 54 | * JCL implementation |
57 | 55 | */ |
56 | @Test | |
58 | 57 | public void testLog4jOverJclConversion() { |
59 | 58 | // running log4j to slf4j conversion |
60 | 59 | LineConverter log4jConverter = new LineConverter(new Log4jRuleSet()); |
23 | 23 | */ |
24 | 24 | package org.slf4j.migrator.line; |
25 | 25 | |
26 | import org.slf4j.migrator.line.LineConverter; | |
26 | import static org.junit.Assert.assertEquals; | |
27 | 27 | |
28 | import junit.framework.TestCase; | |
28 | import org.junit.Test; | |
29 | 29 | |
30 | public class TrivialMatcherTest extends TestCase { | |
30 | public class TrivialMatcherTest { | |
31 | 31 | |
32 | @Test | |
32 | 33 | public void testSimpleReplacement() { |
33 | 34 | LineConverter trivialLC = new LineConverter(new TrivialMatcher()); |
34 | 35 |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
0 | <?xml version="1.0" encoding="UTF-8"?> | |
1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | 3 | |
5 | 4 | <modelVersion>4.0.0</modelVersion> |
6 | 5 | |
7 | 6 | <parent> |
8 | 7 | <groupId>org.slf4j</groupId> |
9 | 8 | <artifactId>slf4j-parent</artifactId> |
10 | <version>1.7.12</version> | |
9 | <version>1.7.13</version> | |
11 | 10 | </parent> |
12 | 11 | |
13 | 12 | <artifactId>slf4j-nop</artifactId> |
17 | 16 | <description>SLF4J NOP Binding</description> |
18 | 17 | <url>http://www.slf4j.org</url> |
19 | 18 | |
20 | ||
21 | 19 | <dependencies> |
22 | 20 | <dependency> |
23 | 21 | <groupId>org.slf4j</groupId> |
25 | 23 | </dependency> |
26 | 24 | </dependencies> |
27 | 25 | |
28 | <build> | |
29 | <plugins> | |
30 | ||
31 | <plugin> | |
32 | <groupId>org.apache.maven.plugins</groupId> | |
33 | <artifactId>maven-jar-plugin</artifactId> | |
34 | <configuration> | |
35 | <archive> | |
36 | <manifestEntries> | |
37 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
38 | <Bundle-Description>${project.description}</Bundle-Description> | |
39 | <Implementation-Version>${project.version}</Implementation-Version> | |
40 | </manifestEntries> | |
41 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
42 | </archive> | |
43 | </configuration> | |
44 | </plugin> | |
45 | </plugins> | |
46 | ||
47 | </build> | |
48 | ||
49 | 26 | </project>⏎ |
23 | 23 | */ |
24 | 24 | package org.slf4j; |
25 | 25 | |
26 | import java.io.Closeable; | |
27 | import java.io.IOException; | |
28 | import junit.framework.TestCase; | |
26 | import static org.junit.Assert.assertNull; | |
27 | ||
28 | import org.junit.Test; | |
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Test whether invoking the SLF4J API causes problems or not. |
33 | 33 | * @author Ceki Gulcu |
34 | 34 | * |
35 | 35 | */ |
36 | public class InvocationTest extends TestCase { | |
36 | public class InvocationTest { | |
37 | 37 | |
38 | public InvocationTest(String arg0) { | |
39 | super(arg0); | |
40 | } | |
41 | ||
42 | protected void setUp() throws Exception { | |
43 | super.setUp(); | |
44 | } | |
45 | ||
46 | protected void tearDown() throws Exception { | |
47 | super.tearDown(); | |
48 | } | |
49 | ||
38 | @Test | |
50 | 39 | public void test1() { |
51 | 40 | Logger logger = LoggerFactory.getLogger("test1"); |
52 | 41 | logger.debug("Hello world."); |
53 | 42 | } |
54 | 43 | |
44 | @Test | |
55 | 45 | public void test2() { |
56 | 46 | Integer i1 = new Integer(1); |
57 | 47 | Integer i2 = new Integer(2); |
75 | 65 | logger.error("Hello world 4.", e); |
76 | 66 | } |
77 | 67 | |
68 | @Test | |
78 | 69 | public void testNull() { |
79 | 70 | Logger logger = LoggerFactory.getLogger("testNull"); |
80 | 71 | logger.debug(null); |
89 | 80 | logger.error(null, e); |
90 | 81 | } |
91 | 82 | |
83 | @Test | |
92 | 84 | public void testMarker() { |
9 |