Codebase list libslf4j-java / 744bc9a
Merge tag 'upstream/1.7.13' Upstream version 1.7.13 Emmanuel Bourg 8 years ago
77 changed file(s) with 821 addition(s) and 776 deletion(s). Raw diff Collapse all Expand all
1212 <echo message="runtime classpath: ${runtime_classpath}" />
1313 <echo message="test classpath: ${test_classpath}" />
1414 <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"/>-->
1519
1620
1721 <path id="path142Binding">
102106 testMatch,
103107 testMultiBinding,
104108 testIncompatibleMultiBinding,
105 testFuture_16Series">
109 testFuture_16Series,
110 testActiveSecurityManager">
106111 </target>
107112
108113
196201 </junit>
197202
198203 </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
199234 </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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
12
1311
1412 <artifactId>integration</artifactId>
1513 <packaging>jar</packaging>
3634 <artifactId>ant-junit</artifactId>
3735 <version>1.6.5</version>
3836 </dependency>
39
4037
4138 <!-- some test run Felix in hosted mode -->
4239 <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"?>
01 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
34 <parent>
45 <groupId>org.slf4j</groupId>
56 <artifactId>slf4j-parent</artifactId>
6 <version>1.7.12</version>
7 <version>1.7.13</version>
78 </parent>
89
910 <modelVersion>4.0.0</modelVersion>
1415 <description>JCL 1.1.1 implemented over SLF4J</description>
1516 <url>http://www.slf4j.org</url>
1617
17
1818 <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
2819 <dependency>
2920 <groupId>org.slf4j</groupId>
3021 <artifactId>slf4j-api</artifactId>
3122 </dependency>
32
3323 <dependency>
3424 <groupId>org.slf4j</groupId>
3525 <artifactId>slf4j-jdk14</artifactId>
3626 <scope>test</scope>
3727 </dependency>
38
3928 </dependencies>
4029
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
6430 </project>
2424
2525 package org.apache.commons.logging;
2626
27 import junit.framework.TestCase;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
2829
29 public class InvokeJCLTest extends TestCase {
30 import org.junit.Test;
3031
32 public class InvokeJCLTest {
33
34 @Test
3135 public void testIsEnabledAPI() {
3236 // assume that we are running over slf4j-jdk14
3337 Log log = LogFactory.getLog(InvokeJCLTest.class);
3943 assertTrue(log.isFatalEnabled());
4044 }
4145
46 @Test
4247 public void testPrintAPI() {
4348 Log log = LogFactory.getLog(InvokeJCLTest.class);
4449 Exception e = new Exception("just testing");
2929 import java.io.ObjectInputStream;
3030 import java.io.ObjectOutputStream;
3131
32 import junit.framework.TestCase;
33
3432 import org.apache.commons.logging.Log;
3533 import org.apache.commons.logging.LogFactory;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
3637 import org.slf4j.impl.JDK14LoggerFactory;
3738 import org.slf4j.spi.LocationAwareLogger;
3839
39 public class SerializationTest extends TestCase {
40 public class SerializationTest {
4041
4142 ObjectInputStream ois;
4243 ByteArrayOutputStream baos = new ByteArrayOutputStream();
4344 ObjectOutputStream oos;
4445
45 public SerializationTest(String name) {
46 super(name);
46 @Before
47 public void setUp() throws Exception {
48 oos = new ObjectOutputStream(baos);
4749 }
4850
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 {
5653 oos.close();
5754 }
5855
6663 resuscitatedLog.isDebugEnabled();
6764 }
6865
66 @Test
6967 public void testSLF4JLog() throws Exception {
7068 JDK14LoggerFactory factory = new JDK14LoggerFactory();
7169 SLF4JLog log = new SLF4JLog(factory.getLogger("x"));
7371 verify();
7472 }
7573
74 @Test
7675 public void testSmoke() throws Exception {
7776 Log log = LogFactory.getLog("testing");
7877 oos.writeObject(log);
7978 verify();
8079 }
8180
81 @Test
8282 public void testLocationAware() throws Exception {
8383 JDK14LoggerFactory factory = new JDK14LoggerFactory();
8484 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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
1211
1312 <artifactId>jul-to-slf4j</artifactId>
3130 </dependency>
3231 </dependencies>
3332
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
6333 </project>
3535 import org.slf4j.LoggerFactory;
3636 import org.slf4j.spi.LocationAwareLogger;
3737
38 // Based on http://bugzilla.slf4j.org/show_bug.cgi?id=38
38 // Based on http://jira.qos.ch/browse/SLF4J-30
3939
4040 /**
4141 * <p>Bridge/route all JUL log records to the SLF4J API.</p>
258258 }
259259 Object[] params = record.getParameters();
260260 // 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
262262 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 }
264270 }
265271 return message;
266272 }
288294 // this is a check to avoid calling the underlying logging system
289295 // with a null message. While it is legitimate to invoke j.u.l. with
290296 // 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
292298 if (message == null) {
293299 message = "";
294300 }
2626 import java.util.logging.Handler;
2727 import java.util.logging.LogManager;
2828
29 import junit.framework.TestCase;
30
3129 import org.apache.log4j.FileAppender;
3230 import org.apache.log4j.PatternLayout;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
3334 import org.slf4j.LoggerFactory;
34
35 public class SLF4JBridgeHandlerPerfTest extends TestCase {
35 public class SLF4JBridgeHandlerPerfTest {
3636
3737 static String LOGGER_NAME = "yay";
3838 static int RUN_LENGTH = 100 * 1000;
4949
5050 Handler[] existingHandlers;
5151
52 public SLF4JBridgeHandlerPerfTest(String arg0) {
53 super(arg0);
54 }
5552
56 protected void setUp() throws Exception {
57 super.setUp();
53 @Before
54 public void setUp() throws Exception {
5855 fileAppender = new FileAppender(new PatternLayout("%r [%t] %p %c %x - %m%n"), "target/test-output/toto.log");
5956
6057 existingHandlers = julRootLogger.getHandlers();
6562 log4jRoot.addAppender(fileAppender);
6663 }
6764
68 protected void tearDown() throws Exception {
69 super.tearDown();
65 @After
66 public void tearDown() throws Exception {
7067 SLF4JBridgeHandler.uninstall();
7168 fileAppender.close();
7269 log4jRoot.getLoggerRepository().resetConfiguration();
9390 return (end - start) * 1.0 / RUN_LENGTH;
9491 }
9592
93 @Test
9694 public void testPerf() {
9795 SLF4JBridgeHandler.install();
9896
2323 */
2424 package org.slf4j.bridge;
2525
26 import static org.junit.Assert.assertEquals;
27
2628 import java.text.MessageFormat;
2729 import java.util.ResourceBundle;
2830 import java.util.logging.Level;
2931
30 import junit.framework.TestCase;
31
3232 import org.apache.log4j.spi.LocationInfo;
3333 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 {
3638
3739 static String LOGGER_NAME = "yay";
3840
4042 org.apache.log4j.Logger log4jRoot;
4143 java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay");
4244
43 public SLF4JBridgeHandlerTest(String arg0) {
44 super(arg0);
45 }
4645
47 protected void setUp() throws Exception {
48 super.setUp();
46 @Before
47 public void setUp() throws Exception {
4948 listAppender.extractLocationInfo = true;
5049 log4jRoot = org.apache.log4j.Logger.getRootLogger();
5150 log4jRoot.addAppender(listAppender);
5251 log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
5352 }
5453
55 protected void tearDown() throws Exception {
56 super.tearDown();
54 @After
55 public void tearDown() throws Exception {
5756 SLF4JBridgeHandler.uninstall();
5857 log4jRoot.getLoggerRepository().resetConfiguration();
5958 }
6059
60 @Test
6161 public void testSmoke() {
6262 SLF4JBridgeHandler.install();
6363 String msg = "msg";
7777 assertEquals("testSmoke", li.getMethodName());
7878 }
7979
80 @Test
8081 public void testLevels() {
8182 SLF4JBridgeHandler.install();
8283 String msg = "msg";
99100 assertLevel(i++, org.apache.log4j.Level.ERROR);
100101 }
101102
103 @Test
102104 public void testLogWithResourceBundle() {
103105 SLF4JBridgeHandler.install();
104106
117119 assertEquals(expectedMsg, le.getMessage());
118120 }
119121
122 @Test
120123 public void testLogWithResourceBundleWithParameters() {
121124 SLF4JBridgeHandler.install();
122125
162165 assertEquals(expectedMsg3, le.getMessage());
163166 }
164167
168 @Test
165169 public void testLogWithPlaceholderNoParameters() {
166170 SLF4JBridgeHandler.install();
167171 String msg = "msg {non-number-string}";
173177 assertEquals(msg, le.getMessage());
174178 }
175179
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
176193 void assertLevel(int index, org.apache.log4j.Level expectedLevel) {
177194 LoggingEvent le = (LoggingEvent) listAppender.list.get(index);
178195 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"
22 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
44 <modelVersion>4.0.0</modelVersion>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.12</version>
9 <version>1.7.13</version>
1010 </parent>
1111
1212
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>
1616 <description>Log4j implemented over SLF4J</description>
1717
18 <url>http://www.slf4j.org</url>
18 <url>http://www.slf4j.org</url>
1919
2020 <licenses>
2121 <license>
2828 <dependency>
2929 <groupId>org.slf4j</groupId>
3030 <artifactId>slf4j-api</artifactId>
31 </dependency>
32
31 </dependency>
3332 <dependency>
3433 <groupId>org.slf4j</groupId>
3534 <artifactId>slf4j-jdk14</artifactId>
3635 <scope>test</scope>
37 </dependency>
36 </dependency>
3837 </dependencies>
3938
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
6239 </project>
1717
1818 import org.apache.log4j.spi.Filter;
1919 import org.apache.log4j.spi.ErrorHandler;
20 import org.apache.log4j.spi.Layout;
2120 import org.apache.log4j.spi.LoggingEvent;
2221
2322 /**
290290 log(FQCN, p, msg, t);
291291 }
292292
293 // See also http://bugzilla.slf4j.org/show_bug.cgi?id=168
293 // See also http://jira.qos.ch/browse/SLF4J-159
294294 public void log(String FQCN, Priority p, Object msg, Throwable t) {
295295 int levelInt = priorityToLevelInt(p);
296296 differentiatedLog(null, FQCN, levelInt, msg, t);
345345 public void setLevel(Level level) {
346346 // nothing to do
347347 }
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 }
348357
349358 }
5050
5151 /**
5252 * 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
5454 * log4j-over-slf4j does not ship with a LoggerFactory implementation. If this
5555 * method is called, the caller must provide his/her own implementation.
5656 *
+0
-20
log4j-over-slf4j/src/main/java/org/apache/log4j/spi/Layout.java less more
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 }
2323 */
2424 package org.apache.log4j;
2525
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;
2731
2832 /**
2933 * @author Ceki G&uuml;c&uuml;
3034 */
31 public class NDCTest extends TestCase {
35 public class NDCTest {
3236
37 @Before
3338 public void setUp() {
3439 assertEquals(0, NDC.getDepth());
3540 }
3641
42 @After
3743 public void tearDown() {
3844 NDC.clear();
3945 }
4046
47 @Test
4148 public void testSmoke() {
4249 NDC.push("a");
4350 String back = NDC.pop();
4451 assertEquals("a", back);
4552 }
4653
54 @Test
4755 public void testPop() {
4856 NDC.push("peek");
4957 String back = NDC.peek();
5058 assertEquals("peek", back);
5159 }
5260
61 @Test
5362 public void testClear() {
5463 NDC.push("clear");
5564 NDC.clear();
2323 */
2424 package org.dummy;
2525
26 import static org.junit.Assert.assertEquals;
27
2628 import java.util.logging.Level;
2729 import java.util.logging.LogRecord;
2830
29 import junit.framework.TestCase;
30
3131 import org.apache.log4j.Category;
3232 import org.apache.log4j.Logger;
33 import org.junit.Test;
34 public class Bug131 {
3335
34 public class Bug131 extends TestCase {
35
36 @Test
3637 public void testBug131() {
3738
3839 ListHandler listHandler = new ListHandler();
2323 */
2424 package org.dummy;
2525
26 import static org.junit.Assert.assertEquals;
27
2628 import java.util.logging.Level;
2729 import java.util.logging.LogRecord;
2830
29 import junit.framework.TestCase;
30
3131 import org.apache.log4j.Category;
3232 import org.apache.log4j.Logger;
33 import org.junit.Test;
3334
34 public class Bug139 extends TestCase {
35 public class Bug139 {
3536
37 @Test
3638 public void test() {
3739 ListHandler listHandler = new ListHandler();
3840 java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
0 <?xml version="1.0" encoding="UTF-8"?>
01 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
56 <parent>
67 <groupId>org.slf4j</groupId>
78 <artifactId>slf4j-parent</artifactId>
8 <version>1.7.12</version>
9 <version>1.7.13</version>
910 </parent>
1011
1112 <artifactId>osgi-over-slf4j</artifactId>
00 <?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"
32 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <groupId>org.slf4j</groupId>
87 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.12</version>
8 <version>1.7.13</version>
109
1110 <packaging>pom</packaging>
1211 <name>SLF4J</name>
3029 <scm>
3130 <url>https://github.com/ceki/slf4j</url>
3231 <connection>git@github.com:qos-ch/slf4j.git</connection>
33 </scm>
32 </scm>
3433
3534 <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>
3638 <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 -->
3842 <slf4j.api.minimum.compatible.version>1.6.0</slf4j.api.minimum.compatible.version>
3943 <cal10n.version>0.8.1</cal10n.version>
4044 <log4j.version>1.2.17</log4j.version>
8084 </dependency>
8185 </dependencies>
8286
83
8487 <dependencyManagement>
8588 <dependencies>
8689
110113
111114 </dependencies>
112115 </dependencyManagement>
113
114116
115117 <build>
116118 <extensions>
123125
124126 <resources>
125127 <resource>
126 <directory>src/main/resources</directory>
128 <directory>${project.basedir}/src/main/resources</directory>
127129 <filtering>true</filtering>
128130 </resource>
129131 </resources>
130132
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
131150 <plugins>
151
132152 <plugin>
133153 <groupId>org.apache.maven.plugins</groupId>
134154 <artifactId>maven-compiler-plugin</artifactId>
135 <version>2.3.2</version>
155 <version>3.3</version>
136156 <configuration>
137 <source>1.5</source>
138 <target>1.5</target>
157 <source>${required.jdk.version}</source>
158 <target>${required.jdk.version}</target>
139159 </configuration>
140160 </plugin>
141161
143163 <groupId>org.apache.maven.plugins</groupId>
144164 <artifactId>maven-jar-plugin</artifactId>
145165 <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>
146179 </plugin>
147180
148181 <plugin>
188221 </configuration>
189222 </plugin>
190223
191 <!-- as suggested in http://bugzilla.slf4j.org/show_bug.cgi?id=152 -->
224 <!-- as suggested in http://jira.qos.ch/browse/SLF4J-143 -->
192225 <plugin>
193226 <groupId>org.codehaus.mojo</groupId>
194227 <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>
35
46 <parent>
57 <groupId>org.slf4j</groupId>
68 <artifactId>slf4j-parent</artifactId>
7 <version>1.7.12</version>
9 <version>1.7.13</version>
810 </parent>
9
10 <modelVersion>4.0.0</modelVersion>
1111
1212 <artifactId>slf4j-android</artifactId>
1313 <packaging>jar</packaging>
3030 </dependency>
3131 </dependencies>
3232
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
6233 </project>
529529 private void formatAndLog(int priority, String format, Object... argArray) {
530530 if (isLoggable(priority)) {
531531 FormattingTuple ft = MessageFormatter.arrayFormat(format, argArray);
532 _log(priority, ft.getMessage(), ft.getThrowable());
532 logInternal(priority, ft.getMessage(), ft.getThrowable());
533533 }
534534 }
535535
536536 private void log(int priority, String message, Throwable throwable) {
537537 if (isLoggable(priority)) {
538 _log(priority, message, throwable);
538 logInternal(priority, message, throwable);
539539 }
540540 }
541541
543543 return Log.isLoggable(name, priority);
544544 }
545545
546 private void _log(int priority, String message, Throwable throwable) {
546 private void logInternal(int priority, String message, Throwable throwable) {
547547 if (throwable != null) {
548548 message += '\n' + Log.getStackTraceString(throwable);
549549 }
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"
22 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
44 <modelVersion>4.0.0</modelVersion>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.12</version>
9 <version>1.7.13</version>
1010 </parent>
1111
1212 <artifactId>slf4j-api</artifactId>
1717
1818 <url>http://www.slf4j.org</url>
1919
20 <dependencies>
21 </dependencies>
22
2320 <build>
2421 <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>
2535 <plugin>
2636 <groupId>org.apache.maven.plugins</groupId>
2737 <artifactId>maven-surefire-plugin</artifactId>
3949 <plugin>
4050 <groupId>org.apache.maven.plugins</groupId>
4151 <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>
5252 <executions>
5353 <execution>
5454 <id>bundle-test-jar</id>
7979 </tasks>
8080 </configuration>
8181 </plugin>
82
8382 </plugins>
8483
8584 </build>
2727 import java.net.URL;
2828 import java.util.Arrays;
2929 import java.util.Enumeration;
30 import java.util.Iterator;
3130 import java.util.LinkedHashSet;
3231 import java.util.List;
3332 import java.util.Set;
8483
8584 // Support for detecting mismatched logger names.
8685 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);
8887
8988 /**
9089 * It is LoggerFactory's responsibility to track version changes and manage
125124 private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder(String msg) {
126125 if (msg == null)
127126 return false;
128 if (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)
127 if (msg.contains("org/slf4j/impl/StaticLoggerBinder"))
129128 return true;
130 if (msg.indexOf("org.slf4j.impl.StaticLoggerBinder") != -1)
129 if (msg.contains("org.slf4j.impl.StaticLoggerBinder"))
131130 return true;
132131 return false;
133132 }
154153 }
155154 } catch (java.lang.NoSuchMethodError nsme) {
156155 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()")) {
158157 INITIALIZATION_STATE = FAILED_INITIALIZATION;
159158 Util.report("slf4j-api 1.6.x (or later) is incompatible with this binding.");
160159 Util.report("Your binding is version 1.5.5 or earlier.");
197196 String requested = StaticLoggerBinder.REQUESTED_API_VERSION;
198197
199198 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)) {
202201 match = true;
203202 }
204203 }
235234 paths = loggerFactoryClassLoader.getResources(STATIC_LOGGER_BINDER_PATH);
236235 }
237236 while (paths.hasMoreElements()) {
238 URL path = (URL) paths.nextElement();
237 URL path = paths.nextElement();
239238 staticLoggerBinderPathSet.add(path);
240239 }
241240 } catch (IOException ioe) {
256255 private static void reportMultipleBindingAmbiguity(Set<URL> staticLoggerBinderPathSet) {
257256 if (isAmbiguousStaticLoggerBinderPathSet(staticLoggerBinderPathSet)) {
258257 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) {
262259 Util.report("Found binding in [" + path + "]");
263260 }
264261 Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation.");
303300 Logger logger = getLogger(clazz.getName());
304301 if (DETECT_LOGGER_NAME_MISMATCH) {
305302 Class<?> autoComputedCallingClass = Util.getCallingClass();
306 if (nonMatchingClasses(clazz, autoComputedCallingClass)) {
303 if (autoComputedCallingClass != null && nonMatchingClasses(clazz, autoComputedCallingClass)) {
307304 Util.report(String.format("Detected logger name mismatch. Given name: \"%s\"; computed name: \"%s\".", logger.getName(),
308305 autoComputedCallingClass.getName()));
309306 Util.report("See " + LOGGER_NAME_MISMATCH_URL + " for an explanation");
338335 throw new IllegalStateException(UNSUCCESSFUL_INIT_MSG);
339336 case ONGOING_INITIALIZATION:
340337 // 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
342339 return TEMP_FACTORY;
343340 }
344341 throw new IllegalStateException("Unreachable code");
9090 } catch (NoClassDefFoundError ncde) {
9191 mdcAdapter = new NOPMDCAdapter();
9292 String msg = ncde.getMessage();
93 if (msg != null && msg.indexOf("StaticMDCBinder") != -1) {
93 if (msg != null && msg.contains("StaticMDCBinder")) {
9494 Util.report("Failed to load class \"org.slf4j.impl.StaticMDCBinder\".");
9595 Util.report("Defaulting to no-operation MDCAdapter implementation.");
9696 Util.report("See " + NO_STATIC_MDC_BINDER_URL + " for further details.");
3131 /**
3232 * Basic MDC implementation, which can be used with logging systems that lack
3333 * out-of-the-box MDC support.
34 *
34 *
3535 * This code was initially inspired by logback's LogbackMDCAdapter. However,
3636 * LogbackMDCAdapter has evolved and is now considerably more sophisticated.
3737 *
3838 * @author Ceki Gulcu
3939 * @author Maarten Bosteels
40 * @author Lukasz Cwik
4041 *
4142 * @since 1.5.0
4243 */
4344 public class BasicMDCAdapter implements MDCAdapter {
4445
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);
5454 }
55 }
56
57 static boolean IS_JDK14 = isJDK14();
55 };
5856
5957 /**
6058 * Put a context value (the <code>val</code> parameter) as identified with
6159 * the <code>key</code> parameter into the current thread's context map.
6260 * Note that contrary to log4j, the <code>val</code> parameter can be null.
63 *
61 *
6462 * <p>
6563 * If the current thread does not have a context map it is created as a side
6664 * effect of this call.
67 *
65 *
6866 * @throws IllegalArgumentException
6967 * in case the "key" parameter is null
7068 */
7270 if (key == null) {
7371 throw new IllegalArgumentException("key cannot be null");
7472 }
75 Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
73 Map<String, String> map = inheritableThreadLocal.get();
7674 if (map == null) {
77 map = Collections.<String, String> synchronizedMap(new HashMap<String, String>());
75 map = new HashMap<String, String>();
7876 inheritableThreadLocal.set(map);
7977 }
8078 map.put(key, val);
8482 * Get the context identified by the <code>key</code> parameter.
8583 */
8684 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);
9088 } else {
9189 return null;
9290 }
9694 * Remove the the context identified by the <code>key</code> parameter.
9795 */
9896 public void remove(String key) {
99 Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
97 Map<String, String> map = inheritableThreadLocal.get();
10098 if (map != null) {
10199 map.remove(key);
102100 }
106104 * Clear all entries in the MDC.
107105 */
108106 public void clear() {
109 Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
107 Map<String, String> map = inheritableThreadLocal.get();
110108 if (map != null) {
111109 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();
119111 }
120112 }
121113
122114 /**
123115 * Returns the keys in the MDC as a {@link Set} of {@link String}s The
124116 * returned value can be null.
125 *
117 *
126118 * @return the keys in the MDC
127119 */
128120 public Set<String> getKeys() {
129 Map<String, String> map = (Map<String, String>) inheritableThreadLocal.get();
121 Map<String, String> map = inheritableThreadLocal.get();
130122 if (map != null) {
131123 return map.keySet();
132124 } else {
135127 }
136128
137129 /**
138 * Return a copy of the current thread's context map.
130 * Return a copy of the current thread's context map.
139131 * Returned value may be null.
140 *
132 *
141133 */
142134 public Map<String, String> getCopyOfContextMap() {
143 Map<String, String> oldMap = (Map<String, String>) inheritableThreadLocal.get();
135 Map<String, String> oldMap = inheritableThreadLocal.get();
144136 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);
150138 } else {
151139 return null;
152140 }
153141 }
154142
155143 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));
158145 }
159
160146 }
100100
101101 int size = referenceList.size();
102102 for (int i = 0; i < size; i++) {
103 Marker m = (Marker) referenceList.get(i);
103 Marker m = referenceList.get(i);
104104 if (referenceToRemove.equals(m)) {
105105 referenceList.remove(i);
106106 return true;
119119 }
120120
121121 if (hasReferences()) {
122 for (int i = 0; i < referenceList.size(); i++) {
123 Marker ref = (Marker) referenceList.get(i);
122 for (Marker ref : referenceList) {
124123 if (ref.contains(other)) {
125124 return true;
126125 }
142141 }
143142
144143 if (hasReferences()) {
145 for (int i = 0; i < referenceList.size(); i++) {
146 Marker ref = (Marker) referenceList.get(i);
144 for (Marker ref : referenceList) {
147145 if (ref.contains(name)) {
148146 return true;
149147 }
181179 StringBuilder sb = new StringBuilder(this.getName());
182180 sb.append(' ').append(OPEN);
183181 while (it.hasNext()) {
184 reference = (Marker) it.next();
182 reference = it.next();
185183 sb.append(reference.getName());
186184 if (it.hasNext()) {
187185 sb.append(SEP);
202202 return new FormattingTuple(messagePattern, argArray, throwableCandidate);
203203 } else { // add the tail string which contains no variables and return
204204 // the result.
205 sbuf.append(messagePattern.substring(i, messagePattern.length()));
205 sbuf.append(messagePattern, i, messagePattern.length());
206206 return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
207207 }
208208 } else {
209209 if (isEscapedDelimeter(messagePattern, j)) {
210210 if (!isDoubleEscaped(messagePattern, j)) {
211211 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);
213213 sbuf.append(DELIM_START);
214214 i = j + 1;
215215 } else {
216216 // The escape character preceding the delimiter start is
217217 // itself escaped: "abc x:\\{}"
218218 // we have to consume one backward slash
219 sbuf.append(messagePattern.substring(i, j - 1));
219 sbuf.append(messagePattern, i, j - 1);
220220 deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
221221 i = j + 2;
222222 }
223223 } else {
224224 // normal case
225 sbuf.append(messagePattern.substring(i, j));
225 sbuf.append(messagePattern, i, j);
226226 deeplyAppendParameter(sbuf, argArray[L], new HashMap<Object[], Object>());
227227 i = j + 2;
228228 }
229229 }
230230 }
231231 // append the characters following the last {} pair.
232 sbuf.append(messagePattern.substring(i, messagePattern.length()));
232 sbuf.append(messagePattern, i, messagePattern.length());
233233 if (L < argArray.length - 1) {
234234 return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
235235 } else {
3434 private Util() {
3535 }
3636
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
3758 /**
3859 * In order to call {@link SecurityManager#getClassContext()}, which is a
3960 * protected method, we add this wrapper which allows the method to be visible
4566 }
4667 }
4768
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 }
4991
5092 /**
5193 * Returns the name of the class which called the invoking method.
5395 * @return the name of the class which called the invoking method.
5496 */
5597 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();
57102 String thisClassName = Util.class.getName();
58103
59104 // Advance until Util is found
2323 */
2424 package org.slf4j;
2525
26 import static org.junit.Assert.*;
27
2628 import java.util.Iterator;
2729
28 import junit.framework.TestCase;
29
30 import org.junit.Test;
3031 import org.slf4j.helpers.BasicMarkerFactory;
3132
3233 /**
3536 * @author Ceki G&uuml;lc&uuml;
3637 * @author Joern Huxhorn
3738 */
38 public class BasicMarkerTest extends TestCase {
39 public class BasicMarkerTest {
3940 static final String BLUE_STR = "BLUE";
4041 static final String RED_STR = "RED";
4142 static final String GREEN_STR = "GREEN";
6869 multiComp.add(comp);
6970 }
7071
72 @Test
7173 public void testPrimitive() {
7274 assertEquals(BLUE_STR, blue.getName());
7375 assertTrue(blue.contains(blue));
7981 assertTrue(blue2.contains(blue));
8082 }
8183
84 @Test
8285 public void testPrimitiveByName() {
8386 assertTrue(blue.contains(BLUE_STR));
8487 }
8588
89 @Test
8690 public void testComposite() {
8791 assertTrue(comp.contains(comp));
8892 assertTrue(comp.contains(blue));
8993 }
9094
95 @Test
9196 public void testCompositeByName() {
9297 assertTrue(comp.contains(COMP_STR));
9398 assertTrue(comp.contains(BLUE_STR));
9499 }
95100
101 @Test
96102 public void testMultiComposite() {
97103 assertTrue(multiComp.contains(comp));
98104 assertTrue(multiComp.contains(blue));
100106 assertFalse(multiComp.contains(red));
101107 }
102108
109 @Test
103110 public void testMultiCompositeByName() {
104111 assertTrue(multiComp.contains(COMP_STR));
105112 assertTrue(multiComp.contains(BLUE_STR));
107114 assertFalse(multiComp.contains(RED_STR));
108115 }
109116
117 @Test
110118 public void testMultiAdd() {
111119 Marker parent = factory.getMarker(PARENT_MARKER_STR);
112120 Marker child = factory.getMarker(CHILD_MARKER_STR);
121129 assertFalse(iterator.hasNext());
122130 }
123131
132 @Test
124133 public void testAddRemove() {
125134 final String NEW_PREFIX = "NEW_";
126135 Marker parent = factory.getMarker(NEW_PREFIX + PARENT_MARKER_STR);
141150 assertFalse(parent.remove(child));
142151 }
143152
153 @Test
144154 public void testSelfRecursion() {
145155 final String diffPrefix = "NEW_" + diff;
146156 final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
154164 assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
155165 }
156166
167 @Test
157168 public void testIndirectRecursion() {
158169 final String diffPrefix = "NEW_" + diff;
159170 final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
174185 assertFalse(parent.contains(NOT_CONTAINED_MARKER_STR));
175186 }
176187
188 @Test
177189 public void testHomonyms() {
178190 final String diffPrefix = "homonym" + diff;
179191 final String PARENT_NAME = diffPrefix + PARENT_MARKER_STR;
2323 */
2424 package org.slf4j;
2525
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28
2629 import java.util.Random;
2730
31 import org.junit.Test;
2832 import org.slf4j.helpers.BasicMarker;
2933 import org.slf4j.helpers.NOPLogger;
3034
31 import junit.framework.TestCase;
32
33 public class NoBindingTest extends TestCase {
35 public class NoBindingTest {
3436
3537 int diff = new Random().nextInt(10000);
3638
39 @Test
3740 public void testLogger() {
3841 Logger logger = LoggerFactory.getLogger(NoBindingTest.class);
3942 logger.debug("hello" + diff);
4043 assertTrue(logger instanceof NOPLogger);
4144 }
4245
43 public void testMDC() {
46 @Test
47 public void testMDC() {
4448 MDC.put("k" + diff, "v");
4549 assertNull(MDC.get("k"));
4650 }
4751
52 @Test
4853 public void testMarker() {
4954 Marker m = MarkerFactory.getMarker("a" + diff);
5055 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 }
2323 */
2424 package org.slf4j.helpers;
2525
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
28
2629 import java.util.Arrays;
2730 import java.util.Random;
2831
29 import junit.framework.TestCase;
32 import org.junit.Test;
3033
3134 /**
3235 * Test that our BubbleSort algorithm is correctly implemented.
3437 * @author Ceki
3538 *
3639 */
37 public class BubbleSortTest extends TestCase {
40 public class BubbleSortTest {
3841
42 @Test
3943 public void testSmoke() {
4044 int[] a = new int[] { 5, 3, 2, 7 };
4145 BubbleSort.sort(a);
4650 assertEquals(7, a[i++]);
4751 }
4852
53 @Test
4954 public void testEmpty() {
5055 int[] a = new int[] {};
5156 BubbleSort.sort(a);
5257 }
5358
59 @Test
5460 public void testSorted() {
5561 int[] a = new int[] { 3, 30, 300, 3000 };
5662 BubbleSort.sort(a);
6167 assertEquals(3000, a[i++]);
6268 }
6369
70 @Test
6471 public void testInverted() {
6572 int[] a = new int[] { 3000, 300, 30, 3 };
6673 BubbleSort.sort(a);
7178 assertEquals(3000, a[i++]);
7279 }
7380
81 @Test
7482 public void testWithSameEntry() {
7583 int[] a = new int[] { 10, 20, 10, 20 };
7684 BubbleSort.sort(a);
8189 assertEquals(20, a[i++]);
8290 }
8391
92 @Test
8493 public void testRandom() {
8594 int len = 100;
8695 Random random = new Random(156);
2525
2626 import java.text.MessageFormat;
2727
28 import junit.framework.TestCase;
2928 import org.junit.Ignore;
29 import org.junit.Test;
3030
3131 @Ignore
32 public class MessageFormatterPerfTest extends TestCase {
32 public class MessageFormatterPerfTest{ //extends TestCase {
3333
3434 Integer i1 = new Integer(1);
3535 Integer i2 = new Integer(2);
3737 //
3838 static long REFERENCE_BIPS = 48416;
3939
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
5040 public void XtestJDKFormatterPerf() {
5141 jdkMessageFormatter(RUN_LENGTH);
5242 double duration = jdkMessageFormatter(RUN_LENGTH);
5343 System.out.println("jdk duration = " + duration + " nanos");
5444 }
5545
46 @Test
5647 public void testSLF4JPerf_OneArg() {
5748 slf4jMessageFormatter_OneArg(RUN_LENGTH);
5849 double duration = slf4jMessageFormatter_OneArg(RUN_LENGTH);
6152 BogoPerf.assertDuration(duration, referencePerf, REFERENCE_BIPS);
6253 }
6354
55 @Test
6456 public void testSLF4JPerf_TwoArg() {
6557 slf4jMessageFormatter_TwoArg(RUN_LENGTH);
6658 double duration = slf4jMessageFormatter_TwoArg(RUN_LENGTH);
2323 */
2424 package org.slf4j.helpers;
2525
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
2629 import java.lang.reflect.InvocationHandler;
2730 import java.lang.reflect.InvocationTargetException;
2831 import java.lang.reflect.Method;
3336 import java.util.List;
3437 import java.util.Set;
3538
36 import junit.framework.TestCase;
39 import org.junit.Test;
3740 import org.slf4j.Logger;
3841
3942 /**
4043 * @author Chetan Mehrotra
4144 */
42 public class SubstitutableLoggerTest extends TestCase {
45 public class SubstitutableLoggerTest {
4346 private static final Set<String> EXCLUDED_METHODS = new HashSet<String>(Arrays.asList("getName"));
4447
48 @Test
4549 public void testDelegate() throws Exception {
4650 SubstituteLogger log = new SubstituteLogger("foo");
4751 assertTrue(log.delegate() instanceof NOPLogger);
2323 */
2424 package org.slf4j.helpers;
2525
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;
2731 import org.slf4j.Logger;
2832
2933 import java.util.Arrays;
3034 import java.util.HashSet;
3135 import java.util.Set;
3236
33 public class SubstituteLoggerFactoryTest extends TestCase {
37 public class SubstituteLoggerFactoryTest {
3438 private SubstituteLoggerFactory factory = new SubstituteLoggerFactory();
3539
40 @Test
3641 public void testFactory() {
3742 Logger log = factory.getLogger("foo");
3843 assertNotNull(log);
4146 assertTrue("Loggers with same name must be same", log == log2);
4247 }
4348
49 @Test
4450 public void testLoggerNameList() {
4551 factory.getLogger("foo1");
4652 factory.getLogger("foo2");
5157 assertEquals(expectedNames, actualNames);
5258 }
5359
60 @Test
5461 public void testLoggers() {
5562 factory.getLogger("foo1");
5663 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"
22 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
44 <modelVersion>4.0.0</modelVersion>
66 <parent>
77 <groupId>org.slf4j</groupId>
88 <artifactId>slf4j-parent</artifactId>
9 <version>1.7.12</version>
9 <version>1.7.13</version>
1010 </parent>
1111
1212 <artifactId>slf4j-ext</artifactId>
4747 </dependencies>
4848
4949 <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>
6051 <plugin>
6152 <groupId>org.apache.maven.plugins</groupId>
6253 <artifactId>maven-surefire-plugin</artifactId>
6354 <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 -->
6556 <printSummary>false</printSummary>
6657 <forkMode>once</forkMode>
6758 <reportFormat>plain</reportFormat>
7364 </configuration>
7465 </plugin>
7566
76
7767 <plugin>
7868 <groupId>org.apache.maven.plugins</groupId>
7969 <artifactId>maven-jar-plugin</artifactId>
8070 <configuration>
8171 <archive>
8272 <manifestEntries>
83 <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version>
84 <Bundle-Description>${project.description}</Bundle-Description>
85 <Implementation-Version>${project.version}</Implementation-Version>
8673 <Premain-Class>org.slf4j.agent.AgentPremain</Premain-Class>
8774 <!-- what is the proper way to specify the maven full name? /ravn -->
8875 <Boot-Class-Path>../../../../javassist/javassist/3.4.GA/javassist-3.4.GA.jar javassist-3.4.GA.jar javassist.jar</Boot-Class-Path>
8976 </manifestEntries>
90 <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
9177 </archive>
92 </configuration>
93 </plugin>
78 </configuration>
79 </plugin>
9480 </plugins>
9581
9682 </build>
9783
98 <reporting>
99 <plugins>
100
101 </plugins>
102 </reporting>
103
10484 </project>
101101 public XLogger(Logger logger) {
102102 // If class B extends A, assuming B does not override method x(), the caller
103103 // 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
105105 super(logger, LoggerWrapper.class.getName());
106106 }
107107
9191 */
9292 public static String getSignature(CtBehavior method) throws NotFoundException {
9393
94 CtClass parameterTypes[] = method.getParameterTypes();
94 CtClass[] parameterTypes = method.getParameterTypes();
9595
9696 CodeAttribute codeAttribute = method.getMethodInfo().getCodeAttribute();
9797
2323 */
2424 package org.slf4j;
2525
26 import junit.framework.TestCase;
26 import static org.junit.Assert.assertEquals;
2727
28 public class NDCTest extends TestCase {
28 import org.junit.Before;
29 import org.junit.Test;
2930
30 protected void setUp() throws Exception {
31 super.setUp();
31 public class NDCTest {
32
33 @Before
34 public void setUp() throws Exception {
3235 MDC.clear();
3336 }
3437
35 protected void tearDown() throws Exception {
36 super.tearDown();
37 }
38
38 @Test
3939 public void testEmpty() {
4040 assertEquals("", NDC.pop());
4141 }
4242
43
44 @Test
4345 public void testSmoke() {
4446 NDC.push("a");
4547 String result = NDC.pop();
4648 assertEquals("a", result);
4749 }
4850
51
52 @Test
4953 public void testSmoke2() {
5054 NDC.push("a");
5155 NDC.push("b");
2323 */
2424 package org.slf4j.cal10n_dummy;
2525
26 import static org.junit.Assert.assertEquals;
27
2628 import java.util.Locale;
2729
28 import junit.framework.TestCase;
29
3030 import org.apache.log4j.spi.LoggingEvent;
31 import org.junit.Before;
32 import org.junit.Test;
3133 import org.slf4j.cal10n.LocLogger;
3234 import org.slf4j.cal10n.LocLoggerFactory;
3335 import org.slf4j.dummyExt.ListAppender;
3436
3537 import ch.qos.cal10n.IMessageConveyor;
3638 import ch.qos.cal10n.MessageConveyor;
37
38 public class LocLoggerTest extends TestCase {
39 public class LocLoggerTest {
3940
4041 ListAppender listAppender;
4142 org.apache.log4j.Logger log4jRoot;
4546
4647 final static String EXPECTED_FILE_NAME = "LocLoggerTest.java";
4748
48 public LocLoggerTest(String name) {
49 super(name);
50 }
5149
50 @Before
5251 public void setUp() throws Exception {
53 super.setUp();
54
5552 // start from a clean slate for each test
5653
5754 listAppender = new ListAppender();
6663 assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
6764 }
6865
69 public void tearDown() throws Exception {
70 super.tearDown();
71 }
7266
67 @Test
7368 public void testSmoke() {
7469 LocLogger locLogger = llFactory_uk.getLocLogger(this.getClass());
7570 locLogger.info(Months.JAN);
2323 */
2424 package org.slf4j.cal10n_dummy;
2525
26 import junit.framework.*;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Suite;
28 import org.junit.runners.Suite.SuiteClasses;
2729
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 {
3533 }
2323 */
2424 package org.slf4j.dummyExt;
2525
26 import static org.junit.Assert.assertEquals;
27
2628 import java.util.Date;
2729 import java.util.Locale;
2830 import java.util.TimeZone;
2931
30 import junit.framework.TestCase;
31
3232 import org.apache.log4j.spi.LocationInfo;
3333 import org.apache.log4j.spi.LoggingEvent;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
3437 import org.slf4j.MDC;
3538 import org.slf4j.ext.EventData;
3639 import org.slf4j.ext.EventLogger;
37
38 public class EventLoggerTest extends TestCase {
40 public class EventLoggerTest {
3941
4042 ListAppender listAppender;
4143 org.apache.log4j.Logger log4;
4244
4345 final static String EXPECTED_FILE_NAME = "EventLoggerTest.java";
4446
45 public EventLoggerTest(String name) {
46 super(name);
47 }
4847
48 @Before
4949 public void setUp() throws Exception {
50 super.setUp();
5150
5251 // start from a clean slate for each test
5352
6766
6867 }
6968
69 @After
7070 public void tearDown() throws Exception {
71 super.tearDown();
7271 MDC.clear();
7372 }
7473
7675 assertEquals(expectedMsg, le.getMessage());
7776 assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
7877 }
79
78
79 @Test
8080 public void testEventLogger() {
8181 EventData data[] = new EventData[2];
8282 data[0] = new EventData();
2323 */
2424 package org.slf4j.dummyExt;
2525
26 import junit.framework.TestCase;
26 import static org.junit.Assert.assertEquals;
2727
28 import org.junit.Test;
2829 import org.slf4j.MDC;
2930 import org.slf4j.ext.MDCStrLookup;
31 public class MDCStrLookupTest {
3032
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
4534 public void testLookup() throws Exception {
4635 MDC.put("key", "value");
4736 MDC.put("number", "2");
2525
2626 import junit.framework.*;
2727
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;
2931
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 {
3735 }
2323 */
2424 package org.slf4j.dummyExt;
2525
26 import junit.framework.TestCase;
26 import static org.junit.Assert.assertEquals;
2727
2828 import org.apache.log4j.spi.LocationInfo;
2929 import org.apache.log4j.spi.LoggingEvent;
30 import org.junit.Before;
31 import org.junit.Test;
3032 import org.slf4j.ext.XLogger;
3133 import org.slf4j.ext.XLoggerFactory;
3234
33 public class XLoggerTest extends TestCase {
35 public class XLoggerTest {
3436
3537 ListAppender listAppender;
3638 org.apache.log4j.Logger log4jRoot;
3739
3840 final static String EXPECTED_FILE_NAME = "XLoggerTest.java";
3941
40 public XLoggerTest(String name) {
41 super(name);
42 }
43
42 @Before
4443 public void setUp() throws Exception {
45 super.setUp();
4644
4745 // start from a clean slate for each test
4846
5149 log4jRoot = org.apache.log4j.Logger.getRootLogger();
5250 log4jRoot.addAppender(listAppender);
5351 log4jRoot.setLevel(org.apache.log4j.Level.TRACE);
54 }
55
56 public void tearDown() throws Exception {
57 super.tearDown();
5852 }
5953
6054 void verify(LoggingEvent le, String expectedMsg) {
7367 assertEquals(le.getLevel().toString(), level.toString());
7468 }
7569
70 @Test
7671 public void testEntering() {
7772 XLogger logger = XLoggerFactory.getXLogger("UnitTest");
7873 logger.entry();
8883 verify((LoggingEvent) listAppender.list.get(2), "entry with (test)");
8984 }
9085
86 @Test
9187 public void testExiting() {
9288 XLogger logger = XLoggerFactory.getXLogger("UnitTest");
9389 logger.exit();
10096 verify((LoggingEvent) listAppender.list.get(2), "exit with (false)");
10197 }
10298
99 @Test
103100 public void testThrowing() {
104101 XLogger logger = XLoggerFactory.getXLogger("UnitTest");
105102 Throwable t = new UnsupportedOperationException("Test");
111108 verifyWithLevelAndException(event, XLogger.Level.DEBUG, "throwing", t);
112109 }
113110
111 @Test
114112 public void testCaught() {
115113 XLogger logger = XLoggerFactory.getXLogger("UnitTest");
116114 long x = 5;
127125 verifyWithLevelAndException((LoggingEvent) listAppender.list.get(1), XLogger.Level.DEBUG, "catching", t);
128126 }
129127
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
131131 public void testLocationExtraction_Bug114() {
132132 XLogger logger = XLoggerFactory.getXLogger("UnitTest");
133133 int line = 135; // requires update if line numbers change
2323 */
2424 package org.slf4j.instrumentation;
2525
26 import junit.framework.TestCase;
26 import static org.junit.Assert.assertEquals;
2727
28 public class ToStringHelperTest extends TestCase {
28 import org.junit.Test;
2929
30 public class ToStringHelperTest {
31
32 @Test
3033 public void testRenderer() {
3134 assertEquals("", "null", ToStringHelper.render(null));
3235 assertEquals("", "a", ToStringHelper.render("a"));
2323 */
2424 package org.slf4j.profiler;
2525
26 import junit.framework.*;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Suite;
28 import org.junit.runners.Suite.SuiteClasses;
2729
28 public class PackageTest extends TestCase {
30 @RunWith(Suite.class)
31 @SuiteClasses({UtilTest.class,
32 ProfilerTest.class})
33 public class PackageTest {
2934
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
3636 }
2323 */
2424 package org.slf4j.profiler;
2525
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;
2729
30 import org.junit.Test;
2831 import org.slf4j.Logger;
2932 import org.slf4j.LoggerFactory;
30
31 public class ProfilerTest extends TestCase {
33 public class ProfilerTest {
3234
3335 Logger logger = LoggerFactory.getLogger(ProfilerTest.class);
3436
35 public void setUp() throws Exception {
36 super.setUp();
37 }
38
37 @Test
3938 public void testSmoke() {
4039 Profiler profiler = new Profiler("SMOKE");
4140 profiler.stop();
4847 assertNull(profiler.getLastTimeInstrument());
4948 }
5049
50 @Test
5151 public void testBasicProfiling() {
5252 Profiler profiler = new Profiler("BAS");
5353
7979 // |-- Total elapsed time [subtask] 7.321 milliseconds.
8080 // |-- elapsed time [doZ] 3.211 milliseconds.
8181 // |-- Total elapsed time [BAS] 30.317 milliseconds.
82 @Test
8283 public void testNestedProfiling() {
8384
8485 Profiler profiler = new Profiler("BAS");
2323 */
2424 package org.slf4j.profiler;
2525
26 import junit.framework.TestCase;
26 import static org.junit.Assert.assertEquals;
2727
28 public class UtilTest extends TestCase {
28 import org.junit.Test;
2929
30 public UtilTest(String name) {
31 super(name);
32 }
30 public class UtilTest {
3331
34 protected void setUp() throws Exception {
35 super.setUp();
36 }
37
38 protected void tearDown() throws Exception {
39 super.tearDown();
40 }
41
32 @Test
4233 public void testSelectDurationUnitForDisplay() throws InterruptedException {
4334 assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(10));
4435 assertEquals(DurationUnit.NANOSECOND, Util.selectDurationUnitForDisplay(9 * Util.NANOS_IN_ONE_MICROSECOND));
0 <?xml version="1.0" encoding="UTF-8"?>
01 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
56 <parent>
67 <groupId>org.slf4j</groupId>
78 <artifactId>slf4j-parent</artifactId>
8 <version>1.7.12</version>
9 <version>1.7.13</version>
910 </parent>
1011
1112 <artifactId>slf4j-jcl</artifactId>
2021 <groupId>org.slf4j</groupId>
2122 <artifactId>slf4j-api</artifactId>
2223 </dependency>
23
2424 <dependency>
2525 <groupId>commons-logging</groupId>
2626 <artifactId>commons-logging</artifactId>
2727 <version>1.1.1</version>
2828 </dependency>
29
3029 </dependencies>
3130
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
5231 </project>
2323 */
2424 package org.slf4j;
2525
26 import static org.junit.Assert.assertNull;
27
2628 import java.util.logging.Level;
2729
28 import junit.framework.TestCase;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
2933
3034 /**
3135 * Test whether invoking the SLF4J API causes problems or not.
3337 * @author Ceki Gulcu
3438 *
3539 */
36 public class InvocationTest extends TestCase {
40 public class InvocationTest {
3741
3842 Level oldLevel;
3943 java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
4044
41 public InvocationTest(String arg0) {
42 super(arg0);
43 }
4445
45 protected void setUp() throws Exception {
46 super.setUp();
46 @Before
47 public void setUp() throws Exception {
4748 oldLevel = root.getLevel();
4849 root.setLevel(Level.OFF);
4950 }
5051
51 protected void tearDown() throws Exception {
52 super.tearDown();
52 @After
53 public void tearDown() throws Exception {
5354 root.setLevel(oldLevel);
5455 }
5556
57 @Test
5658 public void test1() {
5759 Logger logger = LoggerFactory.getLogger("test1");
5860 logger.debug("Hello world.");
5961 }
6062
63 @Test
6164 public void test2() {
6265 Integer i1 = new Integer(1);
6366 Integer i2 = new Integer(2);
8184 logger.error("Hello world 4.", e);
8285 }
8386
87 @Test
8488 public void testNull() {
8589 Logger logger = LoggerFactory.getLogger("testNull");
8690 logger.debug(null);
9599 logger.error(null, e);
96100 }
97101
102 @Test
98103 public void testMarker() {
99104 Logger logger = LoggerFactory.getLogger("testMarker");
100105 Marker blue = MarkerFactory.getMarker("BLUE");
114119 logger.error(blue, "hello {} and {} ", "world", "universe");
115120 }
116121
122 @Test
117123 public void testMDC() {
118124 MDC.put("k", "v");
119125 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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
1211
1312 <artifactId>slf4j-jdk14</artifactId>
14
1513 <packaging>jar</packaging>
1614 <name>SLF4J JDK14 Binding</name>
1715 <description>SLF4J JDK14 Binding</description>
1816 <url>http://www.slf4j.org</url>
19
2017
2118 <dependencies>
2219 <dependency>
3330 </dependency>
3431 </dependencies>
3532
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
5533 </project>
573573 LogRecord record = new LogRecord(level, msg);
574574 record.setLoggerName(getName());
575575 record.setThrown(t);
576 // Note: parameters in record are not set because SLF4J only
577 // supports a single formatting style
576578 fillCallerData(callerFQCN, record);
577579 logger.log(record);
578580
642644 // construction of location data for disabled log
643645 // statements. As of 2008-07-31, callers of this method
644646 // 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
646648 if (logger.isLoggable(julLevel)) {
647649 log(callerFQCN, julLevel, message, t);
648650 }
2323 */
2424 package org.slf4j.impl;
2525
26 import static org.junit.Assert.assertNotNull;
27
2628 import java.util.logging.Handler;
2729 import java.util.logging.LogRecord;
2830 import java.util.logging.Logger;
2931
30 import junit.framework.TestCase;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
3135
32 public class JDK14AdapterLoggerNameTest extends TestCase {
36 public class JDK14AdapterLoggerNameTest {
3337 private MockHandler mockHandler;
3438
35 protected void setUp() throws Exception {
36 super.setUp();
39 @Before
40 public void setUp() throws Exception {
3741 Logger logger = Logger.getLogger("TEST");
3842 mockHandler = new MockHandler();
3943 removeHandlers(logger);
4044 logger.addHandler(mockHandler);
4145 }
4246
43 protected void tearDown() throws Exception {
47 @After
48 public void tearDown() throws Exception {
4449 removeHandlers(Logger.getLogger("TEST"));
45 super.tearDown();
4650 }
4751
52 @Test
4853 public void testLoggerNameusingJdkLogging() throws Exception {
4954 Logger.getLogger("TEST").info("test message");
5055 assertCorrectLoggerName();
5156
5257 }
5358
59 @Test
5460 public void testLoggerNameUsingSlf4j() throws Exception {
5561 JDK14LoggerFactory factory = new JDK14LoggerFactory();
5662 org.slf4j.Logger logger = factory.getLogger("TEST");
2323 */
2424 package org.slf4j.impl;
2525
26 import junit.framework.TestCase;
27
26 import org.junit.Test;
2827 import org.slf4j.Logger;
2928 import org.slf4j.LoggerFactory;
3029 import org.slf4j.helpers.BogoPerf;
3130
32 public class PerfTest extends TestCase {
31 public class PerfTest {
3332
3433 static long REFERENCE_BIPS = 9000;
3534
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
4836 public void testBug72() {
4937
5038 int LEN = 1000 * 1000 * 10;
3333
3434 import junit.framework.Assert;
3535
36 import junit.framework.TestCase;
36 import org.junit.Test;
3737 import org.slf4j.Logger;
3838 import org.slf4j.LoggerFactory;
3939
4040 /**
41 * See http://bugzilla.slf4j.org/show_bug.cgi?id=261
41 * See http://jira.qos.ch/browse/SLF4J-252
4242 * @author Thorbjorn Ravn Andersen
4343 */
44 public class LoggerSerializationTest extends TestCase {
44 public class LoggerSerializationTest {
4545
4646 static class LoggerHolder implements Serializable {
4747 private static final long serialVersionUID = 1L;
5757 }
5858 }
5959
60 @Test
6061 public void testCanLoggerBeSerialized() throws IOException, ClassNotFoundException {
6162
6263 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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
1211
1312 <artifactId>slf4j-log4j12</artifactId>
1615 <name>SLF4J LOG4J-12 Binding</name>
1716 <description>SLF4J LOG4J-12 Binding</description>
1817 <url>http://www.slf4j.org</url>
19
2018
2119 <dependencies>
2220 <dependency>
3028 </dependency>
3129 </dependencies>
3230
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
5231 </project>
4747 * The TRACE level was introduced in log4j version 1.2.12. In order to avoid
4848 * crashing the host application, in the case the log4j version in use predates
4949 * 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>.
5151 *
5252 * @author Ceki G&uuml;lc&uuml;
5353 */
2323 */
2424 package org.slf4j;
2525
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
2631 import java.util.HashMap;
2732 import java.util.Map;
2833
2934 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;
3238
3339 /**
3440 * Test whether invoking the SLF4J API causes problems or not.
3642 * @author Ceki Gulcu
3743 *
3844 */
39 public class InvocationTest extends TestCase {
45 public class InvocationTest {
4046
4147 ListAppender listAppender = new ListAppender();
4248 org.apache.log4j.Logger root;
4349
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);
4655 }
4756
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 {
5759 root.getLoggerRepository().resetConfiguration();
5860 }
59
61
62 @Test
6063 public void test1() {
6164 Logger logger = LoggerFactory.getLogger("test1");
6265 logger.debug("Hello world.");
6366 assertEquals(1, listAppender.list.size());
6467 }
6568
69 @Test
6670 public void test2() {
6771 Integer i1 = new Integer(1);
6872 Integer i2 = new Integer(2);
8993 assertEquals(11, listAppender.list.size());
9094 }
9195
96 @Test
9297 public void testNull() {
9398 Logger logger = LoggerFactory.getLogger("testNull");
9499 logger.trace(null);
105110 assertEquals(8, listAppender.list.size());
106111 }
107112
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
109116 public void testNullParameter_BUG78() {
110117 Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78");
111118 String[] parameters = null;
112119 String msg = "hello {}";
113120
114 logger.debug(msg, parameters);
121 logger.debug(msg, (Object[]) parameters);
122
115123 assertEquals(1, listAppender.list.size());
116124 LoggingEvent e = (LoggingEvent) listAppender.list.get(0);
117125 assertEquals(msg, e.getMessage());
118126 }
119127
128 @Test
120129 public void testMarker() {
121130 Logger logger = LoggerFactory.getLogger("testMarker");
122131 Marker blue = MarkerFactory.getMarker("BLUE");
138147 assertEquals(12, listAppender.list.size());
139148 }
140149
150 @Test
141151 public void testMDC() {
142152 MDC.put("k", "v");
143153 assertNotNull(MDC.get("k"));
158168 }
159169 }
160170
171 @Test
161172 public void testMDCContextMapValues() {
162173 Map<String, String> map = new HashMap<String, String>();
163174 map.put("ka", "va");
2525
2626 import java.util.Random;
2727
28 import junit.framework.TestCase;
29
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
3031 import org.slf4j.Logger;
3132 import org.slf4j.LoggerFactory;
32
33 public class RecursiveInitializationTest extends TestCase {
33 public class RecursiveInitializationTest {
3434
3535 // value of LogManager.DEFAULT_CONFIGURATION_KEY;
3636 static String CONFIG_FILE_KEY = "log4j.configuration";
3737
3838 int diff = new Random().nextInt(10000);
3939
40 protected void setUp() throws Exception {
40 @Before
41 public void setUp() throws Exception {
4142 System.setProperty(CONFIG_FILE_KEY, "recursiveInit.properties");
42 super.setUp();
4343 }
4444
45 protected void tearDown() throws Exception {
45 @After
46 public void tearDown() throws Exception {
4647 System.clearProperty(CONFIG_FILE_KEY);
47 super.tearDown();
4848 }
4949
50 @Test
5051 public void testLog4j() {
5152 Logger logger = LoggerFactory.getLogger("x" + diff);
5253 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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
1211
1312 <artifactId>slf4j-migrator</artifactId>
1615 <name>SLF4J Migrator</name>
1716 <description>SLF4J Migrator</description>
1817
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
4518 </project>
4747 return filename;
4848 }
4949 StringBuilder buf = new StringBuilder(desiredLength);
50 buf.append(filename.substring(0, firstIndex + 1));
50 buf.append(filename, 0, firstIndex + 1);
5151 buf.append(FILLER);
5252 int nextIndex = computeNextIndex(filename, firstIndex);
5353 if (nextIndex != -1) {
2626 import java.io.File;
2727 import java.io.IOException;
2828
29 import junit.framework.TestCase;
30
31 import org.slf4j.migrator.InplaceFileConverter;
29 import org.junit.Ignore;
30 import org.junit.Test;
3231 import org.slf4j.migrator.internal.NopProgressListener;
3332 import org.slf4j.migrator.line.EmptyRuleSet;
33 public class FileConverterTest {
3434
35 public class FileConverterTest extends TestCase {
3635
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
5238 public void XtestNOP() throws IOException {
5339 InplaceFileConverter fc = new InplaceFileConverter(new EmptyRuleSet(), new NopProgressListener());
5440 fc.convert(new File("c:/varargs.txt"));
2525
2626 import java.io.File;
2727
28 import org.slf4j.migrator.Constant;
29 import org.slf4j.migrator.ProjectConverter;
28 import org.junit.Ignore;
29 import org.junit.Test;
3030 import org.slf4j.migrator.internal.NopProgressListener;
3131
32 import junit.framework.TestCase;
33
34 public class ProjectConverterTest extends TestCase {
32 public class ProjectConverterTest {
3533
3634 public void test() {
3735 }
3836
37 @Test
38 @Ignore
3939 public void XtestBarracuda() {
4040 ProjectConverter pc = new ProjectConverter(Constant.LOG4J_TO_SLF4J, new NopProgressListener());
4141 File projectFolder = new File("c:/home/ceki//Varia/Barracuda");
2323 */
2424 package org.slf4j.migrator.helper;
2525
26 import org.slf4j.migrator.helper.Abbreviator;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
2728
28 import junit.framework.TestCase;
29
30 public class AbbreviatorTest extends TestCase {
29 import org.junit.Test;
30 public class AbbreviatorTest {
3131
3232 static final char FS = '/';
3333 static final String INPUT_0 = "/abc/123456/ABC";
3535
3636 RandomHelper rh = new RandomHelper(FS);
3737
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
5039 public void testSmoke() {
5140 {
5241 Abbreviator abb = new Abbreviator(2, 100, FS);
6655 }
6756 }
6857
58 @Test
6959 public void testImpossibleToAbbreviate() {
7060 Abbreviator abb = new Abbreviator(2, 20, FS);
7161 String in = "iczldqwivpgm/mgrmvbjdxrwmqgprdjusth";
7363 assertEquals(in, r);
7464 }
7565
66 @Test
7667 public void testNoFS() {
7768 Abbreviator abb = new Abbreviator(2, 100, FS);
7869 String r = abb.abbreviate("hello");
8071
8172 }
8273
74 @Test
8375 public void testZeroPrefix() {
8476 {
8577 Abbreviator abb = new Abbreviator(0, 100, FS);
8880 }
8981 }
9082
83 @Test
9184 public void testTheories() {
9285 int MAX_RANDOM_FIXED_LEN = 20;
9386 int MAX_RANDOM_AVG_LEN = 20;
2323 */
2424 package org.slf4j.migrator.line;
2525
26 import org.slf4j.migrator.line.JCLRuleSet;
27 import org.slf4j.migrator.line.LineConverter;
26 import static org.junit.Assert.assertEquals;
2827
29 import junit.framework.TestCase;
30
31 public class JCLRuleSetTest extends TestCase {
28 import org.junit.Test;
29 public class JCLRuleSetTest {
3230
3331 LineConverter jclConverter = new LineConverter(new JCLRuleSet());
3432
33 @Test
3534 public void testImportReplacement() {
3635 // LogFactory import replacement
3736 assertEquals("import org.slf4j.LoggerFactory;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.LogFactory;"));
3938 assertEquals("import org.slf4j.Logger;", jclConverter.getOneLineReplacement("import org.apache.commons.logging.Log;"));
4039 }
4140
41
42 @Test
4243 public void testLogFactoryGetLogReplacement() {
4344 // Logger declaration and instanciation without modifier
4445 assertEquals(" Logger l = LoggerFactory.getLogger(MyClass.class);",
6465 jclConverter.getOneLineReplacement("// myLog = LogFactory.getLog(MyClass.class);//logger instanciation"));
6566 }
6667
68 @Test
6769 public void testLogFactoryGetFactoryReplacement() {
6870
6971 // Logger declaration and instanciation without modifier
9092 jclConverter.getOneLineReplacement("// myLog = LogFactory.getFactory().getInstance(MyClass.class);//logger instanciation"));
9193 }
9294
95
96 @Test
9397 public void testLogDeclarationReplacement() {
9498
9599 // simple Logger declaration
105109 assertEquals("//private Logger myLog;", jclConverter.getOneLineReplacement("//private Log myLog;"));
106110 }
107111
112 @Test
108113 public void testMultiLineReplacement() {
109114 // Logger declaration on a line
110115 assertEquals("protected Logger log =", jclConverter.getOneLineReplacement("protected Log log ="));
2323 */
2424 package org.slf4j.migrator.line;
2525
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;
2927
30 import junit.framework.TestCase;
31
32 public class NoConversionTest extends TestCase {
28 import org.junit.Test;
29 public class NoConversionTest {
3330
3431 /**
3532 * This test shows that performing JCL to SLF4J conversion has no impact on
3633 * Log4j implementation
3734 */
35 @Test
3836 public void testJclOverLog4jConversion() {
3937 // running jcl to slf4j conversion
4038 // JCLMatcher jclMatcher =
5553 * This test shows that performing Log4j to SLF4J conversion has no impact on
5654 * JCL implementation
5755 */
56 @Test
5857 public void testLog4jOverJclConversion() {
5958 // running log4j to slf4j conversion
6059 LineConverter log4jConverter = new LineConverter(new Log4jRuleSet());
2323 */
2424 package org.slf4j.migrator.line;
2525
26 import org.slf4j.migrator.line.LineConverter;
26 import static org.junit.Assert.assertEquals;
2727
28 import junit.framework.TestCase;
28 import org.junit.Test;
2929
30 public class TrivialMatcherTest extends TestCase {
30 public class TrivialMatcherTest {
3131
32 @Test
3233 public void testSimpleReplacement() {
3334 LineConverter trivialLC = new LineConverter(new TrivialMatcher());
3435
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">
43
54 <modelVersion>4.0.0</modelVersion>
65
76 <parent>
87 <groupId>org.slf4j</groupId>
98 <artifactId>slf4j-parent</artifactId>
10 <version>1.7.12</version>
9 <version>1.7.13</version>
1110 </parent>
1211
1312 <artifactId>slf4j-nop</artifactId>
1716 <description>SLF4J NOP Binding</description>
1817 <url>http://www.slf4j.org</url>
1918
20
2119 <dependencies>
2220 <dependency>
2321 <groupId>org.slf4j</groupId>
2523 </dependency>
2624 </dependencies>
2725
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
4926 </project>
2323 */
2424 package org.slf4j;
2525
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;
2929
3030 /**
3131 * Test whether invoking the SLF4J API causes problems or not.
3333 * @author Ceki Gulcu
3434 *
3535 */
36 public class InvocationTest extends TestCase {
36 public class InvocationTest {
3737
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
5039 public void test1() {
5140 Logger logger = LoggerFactory.getLogger("test1");
5241 logger.debug("Hello world.");
5342 }
5443
44 @Test
5545 public void test2() {
5646 Integer i1 = new Integer(1);
5747 Integer i2 = new Integer(2);
7565 logger.error("Hello world 4.", e);
7666 }
7767
68 @Test
7869 public void testNull() {
7970 Logger logger = LoggerFactory.getLogger("testNull");
8071 logger.debug(null);
8980 logger.error(null, e);
9081 }
9182
83 @Test
9284 public void testMarker() {
9385 Logger logger = LoggerFactory.getLogger("testMarker");
9486 Marker blue = MarkerFactory.getMarker("BLUE");
108100 logger.error(blue, "hello {} and {} ", "world", "universe");
109101 }
110102
103 @Test
111104 public void testMDC() {
112105 MDC.put("k", "v");
113106 assertNull(MDC.get("k"));
116109 MDC.clear();
117110 }
118111
112 @Test
119113 public void testMDCCloseable() {
120114 MDC.MDCCloseable closeable = MDC.putCloseable("k", "v");
121115 assertNull(MDC.get("k"));
0 <?xml version="1.0" encoding="UTF-8"?>
01 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
56 <parent>
67 <groupId>org.slf4j</groupId>
78 <artifactId>slf4j-parent</artifactId>
8 <version>1.7.12</version>
9 <version>1.7.13</version>
910 </parent>
1011
1112 <artifactId>slf4j-simple</artifactId>
2122 </dependency>
2223 </dependencies>
2324
24
25 <build>
26 <plugins>
27 <plugin>
28 <groupId>org.apache.maven.plugins</groupId>
29 <artifactId>maven-jar-plugin</artifactId>
30 <configuration>
31 <archive>
32 <manifestEntries>
33 <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version>
34 <Bundle-Description>${project.description}</Bundle-Description>
35 <Implementation-Version>${project.version}</Implementation-Version>
36 </manifestEntries>
37 <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
38 </archive>
39 </configuration>
40 </plugin>
41
42 </plugins>
43 </build>
44
45
4625 </project>
7979 public void testTriggerWithProperty() {
8080 setTrialEnabled(true);
8181 LoggerFactory.getLogger(String.class);
82 String s = String.valueOf(byteArrayOutputStream);
8283 assertMismatchDetected(true);
8384 }
8485
8990 public void testTriggerWholeMessage() {
9091 setTrialEnabled(true);
9192 LoggerFactory.getLogger(String.class);
92 assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), String.valueOf(byteArrayOutputStream).contains(
93 "Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\"."));
93 boolean success = String.valueOf(byteArrayOutputStream).contains(
94 "Detected logger name mismatch. Given name: \"java.lang.String\"; " + "computed name: \"org.slf4j.DetectLoggerNameMismatchTest\".");
95 assertTrue("Actual value of byteArrayOutputStream: " + String.valueOf(byteArrayOutputStream), success);
9496 }
9597
9698 /*
2323 */
2424 package org.slf4j;
2525
26 import static org.junit.Assert.assertNull;
27
2628 import java.io.PrintStream;
2729
28 import junit.framework.TestCase;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
2933
3034 /**
3135 * Test whether invoking the SLF4J API causes problems or not.
3337 * @author Ceki Gulcu
3438 *
3539 */
36 public class InvocationTest extends TestCase {
40 public class InvocationTest {
3741
3842 PrintStream old = System.err;
3943
40 public InvocationTest(String arg0) {
41 super(arg0);
42 }
43
44 protected void setUp() throws Exception {
45 super.setUp();
44 @Before
45 public void setUp() throws Exception {
4646 System.setErr(new SilentPrintStream(old));
4747 }
4848
49 protected void tearDown() throws Exception {
50 super.tearDown();
49 @After
50 public void tearDown() throws Exception {
51
5152 System.setErr(old);
5253 }
5354
55 @Test
5456 public void test1() {
5557 Logger logger = LoggerFactory.getLogger("test1");
5658 logger.debug("Hello world.");
5759 }
5860
61 @Test
5962 public void test2() {
6063 Integer i1 = new Integer(1);
6164 Integer i2 = new Integer(2);
7982 logger.error("Hello world 4.", e);
8083 }
8184
82 // http://bugzilla.slf4j.org/show_bug.cgi?id=78
85 // http://jira.qos.ch/browse/SLF4J-69
86 // formerly http://bugzilla.slf4j.org/show_bug.cgi?id=78
87 @Test
8388 public void testNullParameter_BUG78() {
8489 Logger logger = LoggerFactory.getLogger("testNullParameter_BUG78");
8590 String[] parameters = null;
8691 String msg = "hello {}";
87 logger.info(msg, parameters);
92 logger.info(msg, (Object[]) parameters);
8893 }
8994
95 @Test
9096 public void testNull() {
9197 Logger logger = LoggerFactory.getLogger("testNull");
9298 logger.debug(null);
101107 logger.error(null, e);
102108 }
103109
110 @Test
104111 public void testMarker() {
105112 Logger logger = LoggerFactory.getLogger("testMarker");
106113 Marker blue = MarkerFactory.getMarker("BLUE");
120127 logger.error(blue, "hello {} and {} ", "world", "universe");
121128 }
122129
130 @Test
123131 public void testMDC() {
124132 MDC.put("k", "v");
125133 assertNull(MDC.get("k"));