mirror of https://github.com/qos-ch/slf4j
Compare commits
58 Commits
v_2.1.0-al
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
61400453cd | |
|
|
58b66c2c7e | |
|
|
be4841cce8 | |
|
|
d2073bece8 | |
|
|
32a9854cf4 | |
|
|
77936c6f1f | |
|
|
34c9d30af5 | |
|
|
902b463957 | |
|
|
b3c2f16f12 | |
|
|
9468c7a28f | |
|
|
183aaa5070 | |
|
|
c233ea1932 | |
|
|
4b4d533771 | |
|
|
9349d64f95 | |
|
|
0def25ebfa | |
|
|
69c333de28 | |
|
|
2470fad4fd | |
|
|
c2c29fec98 | |
|
|
0597225b5b | |
|
|
f7b34c2e60 | |
|
|
4fa92fc007 | |
|
|
101086ba35 | |
|
|
8ae0efca23 | |
|
|
3ff00870b3 | |
|
|
0df43e9e53 | |
|
|
46b5ea54a6 | |
|
|
5321a975d4 | |
|
|
09111e8c1e | |
|
|
6a04f67fdd | |
|
|
03aa6b915a | |
|
|
7c3b0ef011 | |
|
|
42810107b0 | |
|
|
982e4b067f | |
|
|
dd4486b5c5 | |
|
|
1d82519b07 | |
|
|
5ffbc67def | |
|
|
3386517ad6 | |
|
|
448bca173c | |
|
|
955209464d | |
|
|
c1473c957a | |
|
|
98932348fb | |
|
|
c52da92599 | |
|
|
da91e4f219 | |
|
|
8c4ea8f225 | |
|
|
6b2921a523 | |
|
|
3f4717c44e | |
|
|
d9145fba56 | |
|
|
68ff7064ec | |
|
|
db8cd90c10 | |
|
|
d564304a61 | |
|
|
ef8dda71dd | |
|
|
fe42ecb5f7 | |
|
|
7029a8b7fd | |
|
|
8c873b2e75 | |
|
|
7bcee9aa1f | |
|
|
6fe9c07113 | |
|
|
df562c22d8 | |
|
|
6d39ca8bf9 |
39
README.md
39
README.md
|
|
@ -2,31 +2,33 @@
|
|||
|
||||
The Simple Logging Facade for Java (SLF4J) serves as a simple facade
|
||||
or abstraction for various logging frameworks (e.g. java.util.logging,
|
||||
logback, reload4j, log4j 2.x) allowing the end user to plug in the desired logging
|
||||
framework at deployment time.
|
||||
logback, reload4j, log4j 2.x, logevents, penna, rainbowgum, tinylog)
|
||||
allowing the end user to plug in the desired logging framework at
|
||||
deployment time.
|
||||
|
||||
More information can be found on the [SLF4J website](http://www.slf4j.org).
|
||||
|
||||
# Build Status
|
||||
[](https://travis-ci.org/qos-ch/slf4j)
|
||||
|
||||
# Search org.slf4j artifacts on Maven Central
|
||||
[](https://search.maven.org/search?q=g:org.slf4j%20AND%20v:2.0.%3F)
|
||||
[](https://central.sonatype.com/search?namespace=org.slf4j)
|
||||
|
||||
|
||||
# In case of problems
|
||||
|
||||
In case of problems please do not hesitate to post an e-mail message
|
||||
on the slf4j-user@qos.ch mailing list. However, please do not
|
||||
directly e-mail SLF4J developers. The answer to your question might
|
||||
be useful to other users. Moreover, there are many knowledgeable users
|
||||
on the slf4j-user mailing lists who can quickly answer your
|
||||
questions.
|
||||
on the [slf4j-user@qos.ch](https://mailman.qos.ch/cgi-bin/mailman/listinfo/slf4j-user)
|
||||
mailing list or to start a <a
|
||||
href="https://github.com/qos-ch/slf4j/discussions">discussion</a> on
|
||||
github. However, please do not directly e-mail SLF4J developers. The
|
||||
answer to your question might be useful to other users. Moreover,
|
||||
there are many knowledgeable users on the slf4j-user mailing lists who
|
||||
can quickly answer your questions.
|
||||
|
||||
# Urgent issues
|
||||
|
||||
For urgent issues do not hesitate to [champion a release](https://github.com/sponsors/qos-ch/sponsorships?tier_id=77436).
|
||||
In principle, most championed issues are solved within 3 business days ensued by a release.
|
||||
For urgent issues do not hesitate to [champion a
|
||||
release](https://github.com/sponsors/qos-ch/sponsorships?tier_id=77436).
|
||||
In principle, most championed issues are solved within 3 business days
|
||||
ensued by a release.
|
||||
|
||||
# How to build SLF4J
|
||||
|
||||
|
|
@ -43,14 +45,13 @@ process:
|
|||
1. Start a discussion on the [slf4j-dev mailing
|
||||
list](http://www.slf4j.org/mailing-lists.html) about your proposed
|
||||
change. Alternately, file a [bug
|
||||
report](http://www.slf4j.org/bug-reporting.html) to initiate the
|
||||
discussion. Note that we ask pull requests to be linked to a [Jira
|
||||
ticket](https://jira.qos.ch/).
|
||||
report](https://github.com/qos-ch/slf4j/issues) on github to initiate the
|
||||
discussion.
|
||||
|
||||
2. Fork qos-ch/slf4j. Ideally, create a new branch from your fork for
|
||||
your contribution to make it easier to merge your changes back.
|
||||
|
||||
3. Make your changes on the branch you hopefully created in Step 2. Be
|
||||
3. Make your changes on the branch created in Step 2. Be
|
||||
sure that your code passes existing unit tests. Please add unit tests
|
||||
for your work if appropriate. It usually is.
|
||||
|
||||
|
|
@ -61,10 +62,8 @@ will be automatically rejected by the [DCO GitHub
|
|||
check](https://probot.github.io/apps/dco/) application.
|
||||
|
||||
5. Push your changes to your fork/branch in GitHub. Don't push it to
|
||||
your master! If you do it will make it harder to submit new changes
|
||||
your master! If you do, it will make it harder to submit new changes
|
||||
later.
|
||||
|
||||
6. Submit a pull request to SLF4J from your commit page on GitHub.
|
||||
|
||||
7. Did we mention that you will be asked to link your pull request
|
||||
with a Jira ticket?
|
||||
|
|
|
|||
|
|
@ -82,12 +82,12 @@
|
|||
</target>
|
||||
|
||||
<target name="testAll" depends="init,
|
||||
testNoProvider150,
|
||||
testNoProvider150,
|
||||
testMismatch,
|
||||
testMatch,
|
||||
testMultiBinding,
|
||||
testFuture_16Series,
|
||||
testActiveSecurityManager">
|
||||
testMultiBinding,
|
||||
testFuture_16Series"
|
||||
>
|
||||
</target>
|
||||
|
||||
|
||||
|
|
@ -201,7 +201,7 @@
|
|||
<property name="path_to_policy" value="file:./src/policy/java-under-ant.policy"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- no longer supported in JDK 24 and later -->
|
||||
<target name="testActiveSecurityManager" depends="setPathToPolicy_FromTop, setPathToPolicy_FromIntegration">
|
||||
<junit printsummary="yes" fork="no" haltonfailure="yes">
|
||||
<jvmarg value="-Djava.security.manager"/>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ package org.slf4j;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.slf4j.helpers.Reporter.SLF4J_INTERNAL_VERBOSITY_KEY;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Random;
|
||||
|
|
@ -43,11 +44,13 @@ public class CompatibilityAssertionTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty(SLF4J_INTERNAL_VERBOSITY_KEY, "debug");
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.clearProperty(SLF4J_INTERNAL_VERBOSITY_KEY);
|
||||
System.setErr(old);
|
||||
}
|
||||
|
||||
|
|
@ -56,9 +59,13 @@ public class CompatibilityAssertionTest {
|
|||
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
assertEquals(1, sps.stringList.size());
|
||||
assertEquals(2, sps.stringList.size());
|
||||
|
||||
String s0 = (String) sps.stringList.get(0);
|
||||
assertTrue(s0.contains(msg));
|
||||
assertTrue(s0.startsWith("SLF4J(D): Connected with provider of type [org.slf4j.simple.SimpleServiceProvider]"));
|
||||
|
||||
String s1 = (String) sps.stringList.get(1);
|
||||
assertTrue(s1.contains(msg));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,11 +55,13 @@ public class MultiBindingAssertionTest {
|
|||
String msg = "hello world " + diff;
|
||||
logger.info(msg);
|
||||
List<String> list = sps.stringList;
|
||||
assertMsgContains(list, 0, "Class path contains multiple SLF4J providers.");
|
||||
assertMsgContains(list, 1, "Found provider");
|
||||
assertMsgContains(list, 2, "Found provider");
|
||||
assertMsgContains(list, 3, "See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
|
||||
assertMsgContains(list, 4, "Actual provider is of type [");
|
||||
int line = 0;
|
||||
|
||||
assertMsgContains(list, line++, "Class path contains multiple SLF4J providers.");
|
||||
assertMsgContains(list, line++, "Found provider");
|
||||
assertMsgContains(list, line++, "Found provider");
|
||||
assertMsgContains(list, line++, "See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
|
||||
//assertMsgContains(list, line++, "SLF4J(D): Connected with provider of type [");
|
||||
}
|
||||
|
||||
void assertMsgContains(List<String> strList, int index, String msg) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<name>Apache-2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
<project name="testing-log4j-bridge" default="usage" basedir=".">
|
||||
|
||||
<property name="lbversion" value="0.9.8-SNAPSHOT" />
|
||||
<property name="slf4jversion" value="1.4.2" />
|
||||
<property name="source.home" value="./src/main/java/" />
|
||||
<property name="javac.dest.12" value="./target/classes12/" />
|
||||
<property name="javac.dest.13" value="./target/classes13/" />
|
||||
<property name="lib" value="./lib" />
|
||||
|
||||
<property name="deprecation" value="on" />
|
||||
|
||||
<path id="basic.classpath">
|
||||
<pathelement location="${source.home}" />
|
||||
<pathelement location="${lib}/junit-3.8.1.jar" />
|
||||
</path>
|
||||
|
||||
<path id="log4j12.classpath">
|
||||
<path refid="basic.classpath" />
|
||||
<pathelement location="${javac.dest.12}" />
|
||||
<pathelement location="${lib}/log4j-1.2.14.jar" />
|
||||
</path>
|
||||
|
||||
<path id="log4j13.classpath">
|
||||
<path refid="basic.classpath" />
|
||||
<pathelement location="${javac.dest.13}" />
|
||||
<pathelement location="${lib}/log4j-1.3alpha-8.jar" />
|
||||
</path>
|
||||
|
||||
<path id="los.classpath">
|
||||
<path refid="basic.classpath" />
|
||||
<pathelement location="${lib}/log4j-over-slf4j-${slf4jversion}.jar" />
|
||||
<pathelement location="${lib}/logback-classic-${lbversion}.jar" />
|
||||
<pathelement location="${lib}/logback-core-${lbversion}.jar" />
|
||||
<pathelement location="${lib}/slf4j-api-${slf4jversion}.jar" />
|
||||
</path>
|
||||
|
||||
<!-- ================================================================= -->
|
||||
<!-- Default target -->
|
||||
<!-- ================================================================= -->
|
||||
<target name="usage">
|
||||
<echo>
|
||||
These are some of the targets supported by this ANT build script:
|
||||
|
||||
all - run all available tests
|
||||
refresh - copy required jar files to the lib directory
|
||||
</echo>
|
||||
</target>
|
||||
|
||||
<delete>
|
||||
<fileset dir="." includes="**/*.bak"/>
|
||||
</delete>
|
||||
|
||||
<target name="refresh">
|
||||
<delete>
|
||||
<fileset dir="lib">
|
||||
<include name="logback-*.jar"/>
|
||||
<include name="log4j-bridge-*.jar"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<copy file="../../slf4j-api/target/slf4j-api-${slf4jversion}.jar" todir="lib/"/>
|
||||
<copy file="../target/log4j-over-slf4j-${slf4jversion}.jar" todir="lib/"/>
|
||||
|
||||
</target>
|
||||
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="${javac.dest.12}" />
|
||||
<mkdir dir="${javac.dest.13}" />
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete>
|
||||
<fileset dir="${javac.dest.12}" includes="**" />
|
||||
<fileset dir="${javac.dest.13}" includes="**" />
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="build_log4j12" depends="init">
|
||||
<javac srcdir="${source.home}"
|
||||
destdir="${javac.dest.12}"
|
||||
includes="**/Log4j12Calls.java"
|
||||
deprecation="${deprecation}" debug="on">
|
||||
<classpath refid="log4j12.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="build_log4j13" depends="init">
|
||||
<javac srcdir="${source.home}"
|
||||
destdir="${javac.dest.13}"
|
||||
includes="**/Log4j13Calls.java" deprecation="${deprecation}" debug="on">
|
||||
<classpath refid="log4j13.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="build_loggerTest" depends="init">
|
||||
<javac srcdir="${source.home}"
|
||||
destdir="${javac.dest.12}"
|
||||
includes="**/LoggerTest.java"
|
||||
deprecation="${deprecation}" debug="on">
|
||||
<classpath refid="los.classpath" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- ================================================================= -->
|
||||
<!-- Run tests -->
|
||||
<!-- ================================================================= -->
|
||||
<target name="all" depends="test12, test13, loggerTest" />
|
||||
|
||||
|
||||
<target name="loggerTest" depends="build_loggerTest">
|
||||
<junit printsummary="yes" fork="yes" haltonfailure="yes">
|
||||
<classpath refid="los.classpath" />
|
||||
<classpath location="${javac.dest.12}" />
|
||||
<formatter type="plain" usefile="false" />
|
||||
<test name="test.LoggerTest" />
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="test12" depends="build_log4j12">
|
||||
<junit printsummary="yes" fork="yes" haltonfailure="yes">
|
||||
<classpath refid="los.classpath" />
|
||||
<classpath location="${javac.dest.12}" />
|
||||
<formatter type="plain" usefile="false" />
|
||||
<test name="test.Log4j12Calls" />
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="test13" depends="build_log4j13">
|
||||
<junit printsummary="yes" fork="yes" haltonfailure="yes">
|
||||
<classpath refid="los.classpath" />
|
||||
<classpath location="${javac.dest.13}" />
|
||||
<formatter type="plain" usefile="false" />
|
||||
<test name="test.Log4j13Calls" />
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,17 +0,0 @@
|
|||
|
||||
This directory is used to test the module against various log4j calls.
|
||||
Two test cases simulate the typical calls that one can find in an application
|
||||
that uses either log4j 1.2.x, or log4j 1.3.x.
|
||||
|
||||
In the same directory is a build.xml file that uses ant to
|
||||
compile the test cases with the corresponding log4j version,
|
||||
and to run these tests without log4j in the classpath but with
|
||||
logback jars instead.
|
||||
|
||||
To run the tests, one must have ant installed. Issuing the following command,
|
||||
once in the compatibility directory will launch the tests:
|
||||
|
||||
ant all
|
||||
|
||||
To obtain more information about the use of the log4j-over-slf4j module,
|
||||
please visit http://www.slf4j.org/log4j-over-slf4j.html
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
package test;
|
||||
|
||||
public class DummyObject {
|
||||
|
||||
public String toString() {
|
||||
return "dummy";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/**
|
||||
* Logback: the reliable, generic, fast and flexible logging framework.
|
||||
*
|
||||
* Copyright (C) 1999-2006, QOS.ch
|
||||
*
|
||||
* This library is free software, you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation.
|
||||
*/
|
||||
package test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.MDC;
|
||||
|
||||
/**
|
||||
*
|
||||
* A test case that issues the typical calls
|
||||
* that an application using log4j 1.2 would do.
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
* @author Sébastien Pennec
|
||||
*/
|
||||
public class Log4j12Calls extends TestCase {
|
||||
public static final Logger logger = Logger.getLogger(Log4j12Calls.class);
|
||||
|
||||
public void testLog() {
|
||||
MDC.put("key", "value1");
|
||||
|
||||
logger.trace("Trace level can be noisy");
|
||||
logger.debug("Entering application");
|
||||
logger.info("Violets are blue");
|
||||
logger.warn("Here is a warning");
|
||||
logger.error("Exiting application", new Exception("just testing"));
|
||||
|
||||
MDC.remove("key");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Logback: the reliable, generic, fast and flexible logging framework.
|
||||
*
|
||||
* Copyright (C) 1999-2006, QOS.ch
|
||||
*
|
||||
* This library is free software, you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation.
|
||||
*/
|
||||
|
||||
package test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.MDC;
|
||||
|
||||
/**
|
||||
*
|
||||
* A test case that issues the typical calls
|
||||
* that an application using log4j 1.3 would do.
|
||||
*
|
||||
* @author Ceki Gülcü
|
||||
* @author Sébastien Pennec
|
||||
*/
|
||||
|
||||
public class Log4j13Calls extends TestCase {
|
||||
public static final Logger logger = Logger.getLogger(Log4j12Calls.class);
|
||||
|
||||
public void testLog() {
|
||||
MDC.put("key", "value1");
|
||||
|
||||
logger.trace("Trace level can be noisy");
|
||||
logger.debug("Entering application");
|
||||
logger.info("Violets are blue");
|
||||
logger.warn("Here is a warning");
|
||||
logger.info("The answer is {}.", new Integer(42));
|
||||
logger.info("Number: {} and another one: {}.", new Integer(42), new Integer(24));
|
||||
|
||||
logger.error("Exiting application", new Exception("just testing"));
|
||||
|
||||
MDC.remove("key");
|
||||
|
||||
MDC.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
package test;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.spi.LoggingEvent;
|
||||
import ch.qos.logback.core.read.ListAppender;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
/**
|
||||
* A class that tests the invocation of the org.apache.log4j.Logger class that
|
||||
* belongs to the log4j-bridge package
|
||||
*
|
||||
* @author Sébastien Pennec
|
||||
* @author Ceki Gülcü
|
||||
*/
|
||||
|
||||
public class LoggerTest extends TestCase {
|
||||
|
||||
LoggerContext context;
|
||||
ListAppender<LoggingEvent> appender;
|
||||
ch.qos.logback.classic.Logger logbackLogger;
|
||||
org.apache.log4j.Logger log4jLogger;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
context = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
context.shutdownAndReset();
|
||||
appender = new ListAppender<LoggingEvent>();
|
||||
appender.setContext(context);
|
||||
appender.setName("listAppender");
|
||||
appender.start();
|
||||
ch.qos.logback.classic.Logger lbLogger = context
|
||||
.getLogger(LoggerContext.ROOT_NAME);
|
||||
lbLogger.addAppender(appender);
|
||||
|
||||
log4jLogger = org.apache.log4j.Logger.getLogger(LoggerTest.class);
|
||||
logbackLogger = context.getLogger(LoggerTest.class);
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
appender.stop();
|
||||
context.stop();
|
||||
appender = null;
|
||||
context = null;
|
||||
logbackLogger = null;
|
||||
log4jLogger = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testLogWithObjectMessages() {
|
||||
LoggingEvent event;
|
||||
|
||||
log4jLogger.debug("test");
|
||||
event = appender.list.get(0);
|
||||
assertEquals("test", event.getMessage());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.debug(null);
|
||||
event = appender.list.get(0);
|
||||
assertEquals(null, event.getMessage());
|
||||
appender.list.clear();
|
||||
|
||||
DummyObject dummy = new DummyObject();
|
||||
log4jLogger.debug(dummy);
|
||||
event = appender.list.get(0);
|
||||
assertEquals(dummy.toString(), event.getMessage());
|
||||
appender.list.clear();
|
||||
}
|
||||
|
||||
public void testIsEnabledAPI() {
|
||||
assertFalse(log4jLogger.isTraceEnabled());
|
||||
assertTrue(log4jLogger.isDebugEnabled());
|
||||
assertTrue(log4jLogger.isInfoEnabled());
|
||||
assertTrue(log4jLogger.isWarnEnabled());
|
||||
assertTrue(log4jLogger.isErrorEnabled());
|
||||
}
|
||||
|
||||
public void testPrintAPI() {
|
||||
Exception e = new Exception("just testing");
|
||||
|
||||
log4jLogger.trace(null);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.debug(null);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.debug("debug message");
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.info(null);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.info("info message");
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.warn(null);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.warn("warn message");
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.error(null);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.error("error message");
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.debug(null, e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.debug("debug message", e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.info(null, e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.info("info message", e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.warn(null, e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.warn("warn message", e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.error(null, e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
log4jLogger.error("error message", e);
|
||||
assertEquals(1, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
}
|
||||
|
||||
public void testLogAPI() {
|
||||
log4jLogger.log("x", Level.TRACE, "x", null);
|
||||
assertEquals(0, appender.list.size());
|
||||
|
||||
log4jLogger.log("x", Level.DEBUG, "x", null);
|
||||
log4jLogger.log("x", Level.INFO, "x", null);
|
||||
log4jLogger.log("x", Level.WARN, "x", null);
|
||||
log4jLogger.log("x", Level.ERROR, "x", null);
|
||||
log4jLogger.log("x", Level.FATAL, "x", null);
|
||||
|
||||
assertEquals(5, appender.list.size());
|
||||
appender.list.clear();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache Software Licenses</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<name>Apache-2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
110
parent/pom.xml
110
parent/pom.xml
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-bom</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -24,10 +24,9 @@
|
|||
<inceptionYear>2005</inceptionYear>
|
||||
|
||||
|
||||
|
||||
<properties>
|
||||
<!-- yyyy-MM-dd'T'HH:mm:ss'Z' -->
|
||||
<project.build.outputTimestamp>2023-09-03T16:20:19Z</project.build.outputTimestamp>
|
||||
<project.build.outputTimestamp>2026-05-12T18:37:04Z</project.build.outputTimestamp>
|
||||
<latest.1.version>1.7.36</latest.1.version>
|
||||
<!-- java.util.ServiceLoader requires Java 6 -->
|
||||
<jdk.version>8</jdk.version>
|
||||
|
|
@ -38,14 +37,14 @@
|
|||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!-- used in integration testing -->
|
||||
<cal10n.version>0.8.1</cal10n.version>
|
||||
<reload4j.version>1.2.22</reload4j.version>
|
||||
<reload4j.version>1.2.22</reload4j.version>
|
||||
<logback.version>1.2.10</logback.version>
|
||||
<jcl.version>1.2</jcl.version>
|
||||
<junit.version>4.13.1</junit.version>
|
||||
<maven-site-plugin.version>3.7.1</maven-site-plugin.version>
|
||||
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
|
||||
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
|
||||
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
|
||||
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
|
||||
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
|
||||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
|
||||
|
|
@ -53,7 +52,6 @@
|
|||
<maven-bundle-plugin.version>5.1.9</maven-bundle-plugin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -72,7 +70,7 @@
|
|||
<artifactId>reload4j</artifactId>
|
||||
<version>${reload4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.cal10n</groupId>
|
||||
<artifactId>cal10n-api</artifactId>
|
||||
|
|
@ -147,14 +145,14 @@
|
|||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
</configuration>
|
||||
</execution>
|
||||
</execution>
|
||||
|
||||
<execution>
|
||||
<execution>
|
||||
<id>module-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</goals>
|
||||
<configuration>
|
||||
<release>9</release>
|
||||
<compileSourceRoots>
|
||||
|
|
@ -165,7 +163,6 @@
|
|||
</execution>
|
||||
|
||||
|
||||
|
||||
</executions>
|
||||
|
||||
</plugin>
|
||||
|
|
@ -200,19 +197,19 @@
|
|||
<supportIncrementalBuild>true</supportIncrementalBuild>
|
||||
<!-- populated by the plugin itself -->
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${replacestring;${project.artifactId};-;.}</Bundle-SymbolicName>
|
||||
<Bundle-Vendor>SLF4J.ORG</Bundle-Vendor>
|
||||
<_snapshot/>
|
||||
<_exportcontents>!META-INF.versions.9,*;-noimport:=true</_exportcontents>
|
||||
<Bundle-Description>${project.description}</Bundle-Description>
|
||||
<Bundle-DocURL>${project.url}</Bundle-DocURL>
|
||||
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
||||
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
||||
<Implementation-Version>${project.version}</Implementation-Version>
|
||||
<Implementation-Title>${project.artifactId}</Implementation-Title>
|
||||
<Multi-Release>true</Multi-Release>
|
||||
<_removeheaders>Private-Package,Bundle-SCM, Bundle-Developers, Include-Resource</_removeheaders>
|
||||
</instructions>
|
||||
<Bundle-SymbolicName>${replacestring;${project.artifactId};-;.}</Bundle-SymbolicName>
|
||||
<Bundle-Vendor>SLF4J.ORG</Bundle-Vendor>
|
||||
<_snapshot/>
|
||||
<_exportcontents>!META-INF.versions.9,*;-noimport:=true</_exportcontents>
|
||||
<Bundle-Description>${project.description}</Bundle-Description>
|
||||
<Bundle-DocURL>${project.url}</Bundle-DocURL>
|
||||
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
||||
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
||||
<Implementation-Version>${project.version}</Implementation-Version>
|
||||
<Implementation-Title>${project.artifactId}</Implementation-Title>
|
||||
<Multi-Release>true</Multi-Release>
|
||||
<_removeheaders>Private-Package,Bundle-SCM, Bundle-Developers, Include-Resource</_removeheaders>
|
||||
</instructions>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
|
@ -267,71 +264,8 @@
|
|||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jxr-plugin</artifactId>
|
||||
<version>${maven-jxr-plugin.version}</version>
|
||||
<configuration>
|
||||
<aggregate>true</aggregate>
|
||||
<javadocDir>target/site/apidocs/</javadocDir>
|
||||
<linkJavadoc>true</linkJavadoc>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
<configuration>
|
||||
<linkJavadoc>true</linkJavadoc>
|
||||
<linksource>true</linksource>
|
||||
<aggregate>true</aggregate>
|
||||
<additionalOptions>
|
||||
<additionalOption>-Xdoclint:none</additionalOption>
|
||||
</additionalOptions>
|
||||
<excludePackageNames>org.slf4j.migrator:org.slf4j.migrator.*</excludePackageNames>
|
||||
<sourceFileExcludes>
|
||||
<sourceFileExclude>**/module-info.java</sourceFileExclude>
|
||||
</sourceFileExcludes>
|
||||
|
||||
<groups>
|
||||
<group>
|
||||
<title>SLF4J packages</title>
|
||||
<packages>org.slf4j:org.slf4j.*</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>SLF4J extensions</title>
|
||||
<packages>
|
||||
org.slf4j.cal10n:org.slf4j.profiler:org.slf4j.ext:org.slf4j.instrumentation:org.slf4j.agent
|
||||
</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>Jakarta Commons Logging packages</title>
|
||||
<packages>org.apache.commons.*</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>java.util.logging (JUL) to SLF4J bridge</title>
|
||||
<packages>org.slf4j.bridge</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>Apache log4j</title>
|
||||
<packages>org.apache.log4j:org.apache.log4j.*</packages>
|
||||
</group>
|
||||
</groups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</reporting>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
|
|
|
|||
129
pom.xml
129
pom.xml
|
|
@ -6,28 +6,29 @@
|
|||
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-bom</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<url>http://www.slf4j.org</url>
|
||||
|
||||
|
||||
<name>SLF4J BOM</name>
|
||||
<description>SLF4J project BOM</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||
<name>MIT</name>
|
||||
<url>https://opensource.org/license/mit</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
|
||||
<scm>
|
||||
<url>https://github.com/qos-ch/slf4j</url>
|
||||
<connection>scm:git:https://github.com/qos-ch/slf4j.git</connection>
|
||||
</scm>
|
||||
</scm>
|
||||
|
||||
|
||||
|
||||
<!-- Inspired by Improving the Maven Bill of Materials (BOM) Pattern -->
|
||||
<!-- https://www.garretwilson.com/blog/2023/06/14/improve-maven-bom-pattern -->
|
||||
<modules>
|
||||
|
|
@ -38,7 +39,7 @@
|
|||
<module>slf4j-jdk14</module>
|
||||
<module>slf4j-jdk-platform-logging</module>
|
||||
<module>slf4j-log4j12</module>
|
||||
<module>slf4j-reload4j</module>
|
||||
<module>slf4j-reload4j</module>
|
||||
<module>slf4j-ext</module>
|
||||
<module>jcl-over-slf4j</module>
|
||||
<module>log4j-over-slf4j</module>
|
||||
|
|
@ -48,6 +49,10 @@
|
|||
<module>slf4j-migrator</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<central-publishing-maven-plugin.version>0.9.0</central-publishing-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
|
|
@ -68,7 +73,7 @@
|
|||
<artifactId>slf4j-nop</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
|
|
@ -81,49 +86,49 @@
|
|||
<artifactId>slf4j-jdk-platform-logging</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-reload4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-ext</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jul-to-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>osgi-over-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
|
@ -145,8 +150,96 @@
|
|||
</developer>
|
||||
</developers>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<configuration>
|
||||
<verbose>true</verbose>
|
||||
<skippedModules>
|
||||
slf4j-jdk-platform-logging,slf4j-migrator,osgi-over-slf4j
|
||||
</skippedModules>
|
||||
<detectLinks>true</detectLinks>
|
||||
<doctitle>SLF4J project modules ${project.version}</doctitle>
|
||||
<windowtitle>SLF4J javadoc</windowtitle>
|
||||
<bottom><![CDATA[Copyright © 2005-{currentYear} QOS.CH Sarl. All rights reserved]]></bottom>
|
||||
<linksource>true</linksource>
|
||||
<additionalOptions>
|
||||
<additionalOption>-Xdoclint:none</additionalOption>
|
||||
</additionalOptions>
|
||||
<groups>
|
||||
<group>
|
||||
<title>SLF4J API packages</title>
|
||||
<packages>org.slf4j:org.slf4j.spi:org.slf4j.event:org.slf4j.helpers</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>slf4j-simple package</title>
|
||||
<packages>org.slf4j.simple</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>slf4j-nop package</title>
|
||||
<packages>org.slf4j.nop</packages>
|
||||
</group>
|
||||
|
||||
|
||||
<group>
|
||||
<title>slf4j-jdk14 package</title>
|
||||
<packages>org.slf4j.jul</packages>
|
||||
</group>
|
||||
|
||||
|
||||
<group>
|
||||
<title>slf4j-reload4j package</title>
|
||||
<packages>org.slf4j.reload4j</packages>
|
||||
</group>
|
||||
|
||||
|
||||
<group>
|
||||
<title>SLF4J extensions</title>
|
||||
<packages>
|
||||
org.slf4j.cal10n:org.slf4j.profiler:org.slf4j.ext:org.slf4j.instrumentation:org.slf4j.agent
|
||||
</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>Jakarta Commons Logging packages</title>
|
||||
<packages>org.apache.commons.*</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>java.util.logging (JUL) to SLF4J bridge</title>
|
||||
<packages>org.slf4j.bridge</packages>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<title>log4j-over-slf4j redirection</title>
|
||||
<packages>org.apache.log4j:org.apache.log4j.*</packages>
|
||||
</group>
|
||||
</groups>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>${central-publishing-maven-plugin.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<excludeArtifacts>integration</excludeArtifacts>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
|
||||
<profile>
|
||||
<id>sign-artifacts</id>
|
||||
<build>
|
||||
|
|
@ -169,5 +262,5 @@
|
|||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
#JDK8 - mvn site:site
|
||||
#rscpSLF4J apidocs/
|
||||
|
||||
# JDK 11+
|
||||
# adding the following
|
||||
#mvn -Ddoclint=none -Dadditionalparam=-Xdoclint:none javadoc:aggregate
|
||||
|
||||
|
||||
#mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${VERSION_NUMBER}
|
||||
|
||||
|
|
@ -42,8 +46,9 @@ echoRunAndCheck "$MVN install"
|
|||
|
||||
if [ ! -z "$PASS" ]
|
||||
then
|
||||
export GPG_TTY=$(tty)
|
||||
echoRunAndCheck "$MVN deploy -P javadocjar,sign-artifacts"
|
||||
# WARNING deploying without cleaning may leave stale MANIFEST files
|
||||
export GPG_TTY=$(tty)
|
||||
echoRunAndCheck "$MVN deploy -P javadocjar,sign-artifacts"
|
||||
fi
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import org.slf4j.helpers.Reporter;
|
|||
import org.slf4j.helpers.SubstituteLogger;
|
||||
import org.slf4j.helpers.SubstituteServiceProvider;
|
||||
import org.slf4j.helpers.Util;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.slf4j.spi.SLF4JServiceProvider;
|
||||
|
||||
/**
|
||||
|
|
@ -82,6 +83,9 @@ public final class LoggerFactory {
|
|||
static final String UNSUCCESSFUL_INIT_URL = CODES_PREFIX + "#unsuccessfulInit";
|
||||
static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory in failed state. Original exception was thrown EARLIER. See also "
|
||||
+ UNSUCCESSFUL_INIT_URL;
|
||||
|
||||
static final String CONNECTED_WITH_MSG = "Connected with provider of type [";
|
||||
|
||||
/**
|
||||
* System property for explicitly setting the provider class. If set and the provider could be instantiated,
|
||||
* then the service loading mechanism will be bypassed.
|
||||
|
|
@ -192,6 +196,7 @@ public final class LoggerFactory {
|
|||
reportMultipleBindingAmbiguity(providersList);
|
||||
if (providersList != null && !providersList.isEmpty()) {
|
||||
PROVIDER = providersList.get(0);
|
||||
earlyBindMDCAdapter();
|
||||
// SLF4JServiceProvider.initialize() is intended to be called here and nowhere else.
|
||||
PROVIDER.initialize();
|
||||
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
|
||||
|
|
@ -212,6 +217,19 @@ public final class LoggerFactory {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of PROVIDER.getMDCAdapter() can be null while PROVIDER has not yet initialized.
|
||||
*
|
||||
* However, SLF4JServiceProvider implementations are expected to initialize their internal
|
||||
* MDCAdapter field in their constructor or on field declaration.
|
||||
*/
|
||||
private static void earlyBindMDCAdapter() {
|
||||
MDCAdapter mdcAdapter = PROVIDER.getMDCAdapter();
|
||||
if(mdcAdapter != null) {
|
||||
MDC.setMDCAdapter(mdcAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
static SLF4JServiceProvider loadExplicitlySpecified(ClassLoader classLoader) {
|
||||
String explicitlySpecified = System.getProperty(PROVIDER_PROPERTY_KEY);
|
||||
if (null == explicitlySpecified || explicitlySpecified.isEmpty()) {
|
||||
|
|
@ -403,9 +421,16 @@ public final class LoggerFactory {
|
|||
}
|
||||
|
||||
private static void reportActualBinding(List<SLF4JServiceProvider> providerList) {
|
||||
// binderPathSet can be null under Android
|
||||
if (!providerList.isEmpty() && isAmbiguousProviderList(providerList)) {
|
||||
// impossible since a provider has been found
|
||||
if (providerList.isEmpty()) {
|
||||
throw new IllegalStateException("No providers were found which is impossible after successful initialization.");
|
||||
}
|
||||
|
||||
if (isAmbiguousProviderList(providerList)) {
|
||||
Reporter.info("Actual provider is of type [" + providerList.get(0) + "]");
|
||||
} else {
|
||||
SLF4JServiceProvider provider = providerList.get(0);
|
||||
Reporter.debug(CONNECTED_WITH_MSG + provider.getClass().getName() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,7 @@ import java.io.Closeable;
|
|||
import java.util.Deque;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.helpers.BasicMDCAdapter;
|
||||
import org.slf4j.helpers.NOPMDCAdapter;
|
||||
import org.slf4j.helpers.Reporter;
|
||||
import org.slf4j.helpers.Util;
|
||||
import org.slf4j.helpers.*;
|
||||
import org.slf4j.spi.MDCAdapter;
|
||||
import org.slf4j.spi.SLF4JServiceProvider;
|
||||
|
||||
|
|
@ -66,9 +63,9 @@ import org.slf4j.spi.SLF4JServiceProvider;
|
|||
public class MDC {
|
||||
|
||||
static final String NULL_MDCA_URL = "http://www.slf4j.org/codes.html#null_MDCA";
|
||||
private static final String MDC_APAPTER_CANNOT_BE_NULL_MESSAGE = "MDCAdapter cannot be null. See also " + NULL_MDCA_URL;
|
||||
private static final String MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE = "MDCAdapter cannot be null. See also " + NULL_MDCA_URL;
|
||||
static final String NO_STATIC_MDC_BINDER_URL = "http://www.slf4j.org/codes.html#no_static_mdc_binder";
|
||||
static MDCAdapter mdcAdapter;
|
||||
static MDCAdapter MDC_ADAPTER;
|
||||
|
||||
/**
|
||||
* An adapter to remove the key when done.
|
||||
|
|
@ -88,14 +85,30 @@ public class MDC {
|
|||
private MDC() {
|
||||
}
|
||||
|
||||
static {
|
||||
private static MDCAdapter getMDCAdapterGivenByProvider() {
|
||||
SLF4JServiceProvider provider = LoggerFactory.getProvider();
|
||||
if (provider != null) {
|
||||
mdcAdapter = provider.getMDCAdapter();
|
||||
if(provider != null) {
|
||||
// If you wish to change the mdc adapter, setting the MDC.MDCAdapter variable might be insufficient.
|
||||
// Keep in mind that the provider *might* perform additional internal mdcAdapter assignments that
|
||||
// you would also need to replicate/adapt.
|
||||
|
||||
// obtain and attach the MDCAdapter from the provider
|
||||
|
||||
final MDCAdapter anAdapter = provider.getMDCAdapter();
|
||||
emitTemporaryMDCAdapterWarningIfNeeded(provider);
|
||||
return anAdapter;
|
||||
} else {
|
||||
Reporter.error("Failed to find provider.");
|
||||
Reporter.error("Defaulting to no-operation MDCAdapter implementation.");
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
return new NOPMDCAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
private static void emitTemporaryMDCAdapterWarningIfNeeded(SLF4JServiceProvider provider) {
|
||||
boolean isSubstitute = provider instanceof SubstituteServiceProvider;
|
||||
if(isSubstitute) {
|
||||
Reporter.info("Temporary mdcAdapter given by SubstituteServiceProvider.");
|
||||
Reporter.info("This mdcAdapter will be replaced after backend initialization has completed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,10 +131,10 @@ public class MDC {
|
|||
if (key == null) {
|
||||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
if (getMDCAdapter() == null) {
|
||||
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
mdcAdapter.put(key, val);
|
||||
getMDCAdapter().put(key, val);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -174,10 +187,8 @@ public class MDC {
|
|||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
return mdcAdapter.get(key);
|
||||
mdcAdapterNullCheck();
|
||||
return getMDCAdapter().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,20 +206,16 @@ public class MDC {
|
|||
throw new IllegalArgumentException("key parameter cannot be null");
|
||||
}
|
||||
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
mdcAdapter.remove(key);
|
||||
mdcAdapterNullCheck();
|
||||
getMDCAdapter().remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all entries in the MDC of the underlying implementation.
|
||||
*/
|
||||
public static void clear() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
mdcAdapter.clear();
|
||||
mdcAdapterNullCheck();
|
||||
getMDCAdapter().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -219,10 +226,8 @@ public class MDC {
|
|||
* @since 1.5.1
|
||||
*/
|
||||
public static Map<String, String> getCopyOfContextMap() {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
return mdcAdapter.getCopyOfContextMap();
|
||||
mdcAdapterNullCheck();
|
||||
return getMDCAdapter().getCopyOfContextMap();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,23 +242,38 @@ public class MDC {
|
|||
* @since 1.5.1
|
||||
*/
|
||||
public static void setContextMap(Map<String, String> contextMap) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
mdcAdapter.setContextMap(contextMap);
|
||||
mdcAdapterNullCheck();
|
||||
getMDCAdapter().setContextMap(contextMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MDCAdapter instance currently in use.
|
||||
*
|
||||
*
|
||||
* Since 2.0.17, if the MDCAdapter instance is null, then this method set it to use
|
||||
* the adapter returned by the SLF4JProvider. However, in the vast majority of cases
|
||||
* the MDCAdapter will be set earlier (during initialization) by {@link LoggerFactory}.
|
||||
*
|
||||
* @return the MDcAdapter instance currently in use.
|
||||
* @since 1.4.2
|
||||
*/
|
||||
public static MDCAdapter getMDCAdapter() {
|
||||
return mdcAdapter;
|
||||
if(MDC_ADAPTER == null) {
|
||||
MDC_ADAPTER = getMDCAdapterGivenByProvider();
|
||||
}
|
||||
return MDC_ADAPTER;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set MDCAdapter instance to use.
|
||||
*
|
||||
* @since 2.0.17
|
||||
*/
|
||||
static void setMDCAdapter(MDCAdapter anMDCAdapter) {
|
||||
if(anMDCAdapter == null) {
|
||||
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
MDC_ADAPTER = anMDCAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a value into the deque(stack) referenced by 'key'.
|
||||
|
|
@ -263,28 +283,24 @@ public class MDC {
|
|||
* @since 2.0.0
|
||||
*/
|
||||
static public void pushByKey(String key, String value) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
mdcAdapter.pushByKey(key, value);
|
||||
mdcAdapterNullCheck();
|
||||
getMDCAdapter().pushByKey(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the stack referenced by 'key' and return the value possibly null.
|
||||
* Pop the <b>stack</b> referenced by 'key' and return the value possibly null.
|
||||
*
|
||||
* @param key identifies the deque(stack)
|
||||
* @return the value just popped. May be null/
|
||||
* @since 2.0.0
|
||||
*/
|
||||
static public String popByKey(String key) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
return mdcAdapter.popByKey(key);
|
||||
mdcAdapterNullCheck();
|
||||
return getMDCAdapter().popByKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the deque(stack) referenced by 'key'. May be null.
|
||||
* Returns a copy of the <b>deque(stack)</b> referenced by 'key'. May be null.
|
||||
*
|
||||
* @param key identifies the stack
|
||||
* @return copy of stack referenced by 'key'. May be null.
|
||||
|
|
@ -292,9 +308,13 @@ public class MDC {
|
|||
* @since 2.0.0
|
||||
*/
|
||||
public Deque<String> getCopyOfDequeByKey(String key) {
|
||||
if (mdcAdapter == null) {
|
||||
throw new IllegalStateException(MDC_APAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
mdcAdapterNullCheck();
|
||||
return getMDCAdapter().getCopyOfDequeByKey(key);
|
||||
}
|
||||
|
||||
private static void mdcAdapterNullCheck() {
|
||||
if (getMDCAdapter() == null) {
|
||||
throw new IllegalStateException(MDC_ADAPTER_CANNOT_BE_NULL_MESSAGE);
|
||||
}
|
||||
return mdcAdapter.getCopyOfDequeByKey(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,10 @@ public interface LoggingEvent {
|
|||
|
||||
Object[] getArgumentArray();
|
||||
|
||||
/**
|
||||
* List of markers in the event, might be null.
|
||||
* @return markers in the event, might be null.
|
||||
*/
|
||||
List<Marker> getMarkers();
|
||||
|
||||
List<KeyValuePair> getKeyValuePairs();
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ package org.slf4j.helpers;
|
|||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* An internally used class for reporting internal messages generated by SLF4J itself during initialization.
|
||||
* An internally used class for reporting internal messages generated by SLF4J itself, typically
|
||||
* during initialization.
|
||||
*
|
||||
* <p>
|
||||
* Internal reporting is performed by calling the {@link #info(String)}, {@link #warn(String)} (String)}
|
||||
* {@link #error(String)} (String)} and {@link #error(String, Throwable)} methods.
|
||||
* Internal reporting is performed by calling the {@link #debug(String)}, {@link #info(String)},
|
||||
* {@link #warn(String)} (String)} {@link #error(String)} (String)} and
|
||||
* {@link #error(String, Throwable)} methods.
|
||||
* </p>
|
||||
* <p>See {@link #SLF4J_INTERNAL_VERBOSITY_KEY} and {@link #SLF4J_INTERNAL_REPORT_STREAM_KEY} for
|
||||
* configuration options.</p>
|
||||
|
|
@ -23,7 +25,7 @@ public class Reporter {
|
|||
* this class is used internally by Reporter
|
||||
*/
|
||||
private enum Level {
|
||||
INFO(1), WARN(2), ERROR(3);
|
||||
DEBUG(0), INFO(1), WARN(2), ERROR(3);
|
||||
|
||||
int levelInt;
|
||||
|
||||
|
|
@ -40,6 +42,7 @@ public class Reporter {
|
|||
Stderr, Stdout;
|
||||
}
|
||||
|
||||
static final String SLF4J_DEBUG_PREFIX = "SLF4J(D): ";
|
||||
static final String SLF4J_INFO_PREFIX = "SLF4J(I): ";
|
||||
static final String SLF4J_WARN_PREFIX = "SLF4J(W): ";
|
||||
static final String SLF4J_ERROR_PREFIX = "SLF4J(E): ";
|
||||
|
|
@ -62,11 +65,11 @@ public class Reporter {
|
|||
public static final String SLF4J_INTERNAL_VERBOSITY_KEY = "slf4j.internal.verbosity";
|
||||
|
||||
|
||||
static private final TargetChoice TARGET_CHOICE = initTargetChoice();
|
||||
static private final TargetChoice TARGET_CHOICE = getTargetChoice();
|
||||
|
||||
static private final Level INTERNAL_VERBOSITY = initVerbosity();
|
||||
|
||||
static private TargetChoice initTargetChoice() {
|
||||
static private TargetChoice getTargetChoice() {
|
||||
String reportStreamStr = System.getProperty(SLF4J_INTERNAL_REPORT_STREAM_KEY);
|
||||
|
||||
if(reportStreamStr == null || reportStreamStr.isEmpty()) {
|
||||
|
|
@ -88,6 +91,10 @@ public class Reporter {
|
|||
return Level.INFO;
|
||||
}
|
||||
|
||||
if(verbosityStr.equalsIgnoreCase("DEBUG")) {
|
||||
return Level.DEBUG;
|
||||
}
|
||||
|
||||
if(verbosityStr.equalsIgnoreCase("ERROR")) {
|
||||
return Level.ERROR;
|
||||
}
|
||||
|
|
@ -97,6 +104,7 @@ public class Reporter {
|
|||
return Level.WARN;
|
||||
}
|
||||
|
||||
// anything else including verbosityStr.equalsIgnoreCase("INFO")
|
||||
return Level.INFO;
|
||||
}
|
||||
|
||||
|
|
@ -114,13 +122,30 @@ public class Reporter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an internal message of level DEBUG. Message text is prefixed with the string "SLF4J(D)",
|
||||
* with (D) standing as a shorthand for DEBUG.
|
||||
*
|
||||
* <p>Messages of level DEBUG are be enabled when the {@link #SLF4J_INTERNAL_VERBOSITY_KEY}
|
||||
* system property is set to "DEBUG" and disabled when set to "INFO", "WARN" or "ERROR". By default,
|
||||
* {@link #SLF4J_INTERNAL_VERBOSITY_KEY} is set to "INFO".</p>
|
||||
*
|
||||
* @param msg the message text
|
||||
* @since 2.0.16
|
||||
*/
|
||||
public static void debug(String msg) {
|
||||
if(isEnabledFor(Level.DEBUG)) {
|
||||
getTarget().println(SLF4J_DEBUG_PREFIX + msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an internal message of level INFO. Message text is prefixed with the string "SLF4J(I)", with
|
||||
* (I) standing as a shorthand for INFO.
|
||||
*
|
||||
* <p>Messages of level INFO are be enabled when the {@link #SLF4J_INTERNAL_VERBOSITY_KEY} system property is
|
||||
* set to "INFO" and disabled when set to "WARN" or "ERROR". By default, {@link #SLF4J_INTERNAL_VERBOSITY_KEY} is
|
||||
* set to "INFO".</p>
|
||||
* set to "DEBUG" or "INFO" and disabled when set to "WARN" or "ERROR". By default,
|
||||
* {@link #SLF4J_INTERNAL_VERBOSITY_KEY} is set to "INFO".</p>
|
||||
*
|
||||
* @param msg the message text
|
||||
*/
|
||||
|
|
@ -136,8 +161,8 @@ public class Reporter {
|
|||
* (W) standing as a shorthand for WARN.
|
||||
*
|
||||
* <p>Messages of level WARN are be enabled when the {@link #SLF4J_INTERNAL_VERBOSITY_KEY} system property is
|
||||
* set to "INFO" or "WARN" and disabled when set to "ERROR". By default, {@link #SLF4J_INTERNAL_VERBOSITY_KEY} is
|
||||
* set to "INFO".</p>
|
||||
* set to "DEBUG", "INFO" or "WARN" and disabled when set to "ERROR". By default,
|
||||
* {@link #SLF4J_INTERNAL_VERBOSITY_KEY} is set to "INFO".</p>
|
||||
*
|
||||
* @param msg the message text
|
||||
*/
|
||||
|
|
@ -147,7 +172,6 @@ public class Reporter {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Report an internal message of level "ERROR accompanied by a {@link Throwable}.
|
||||
* Message text is prefixed with the string "SLF4J(E)", with (E) standing as a shorthand for ERROR.
|
||||
|
|
@ -164,10 +188,9 @@ public class Reporter {
|
|||
t.printStackTrace(getTarget());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Report an internal message of level "ERROR". Message text is prefixed with the string "SLF4J(E)", with
|
||||
* (E) standing as a shorthand for ERROR.
|
||||
* Report an internal message of level "ERROR". Message text is prefixed with the string "SLF4J(E)",
|
||||
* with (E) standing as a shorthand for ERROR.
|
||||
*
|
||||
* <p>Messages of level ERROR are always enabled.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2024 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.slf4j.helpers;
|
||||
|
||||
/**
|
||||
* Various utility methods
|
||||
*
|
||||
* @since 2.0.14
|
||||
*/
|
||||
public class Slf4jEnvUtil {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current version of slf4j, or null if data is not available.
|
||||
*
|
||||
* @return current version or null if missing version data
|
||||
* @since 2.0.14
|
||||
*/
|
||||
static public String slf4jVersion() {
|
||||
// String moduleVersion = slf4jVersionByModule();
|
||||
// if(moduleVersion != null)
|
||||
// return moduleVersion;
|
||||
|
||||
Package pkg = Slf4jEnvUtil.class.getPackage();
|
||||
if(pkg == null) {
|
||||
return null;
|
||||
}
|
||||
final String pkgVersion = pkg.getImplementationVersion();
|
||||
return pkgVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of slf4j via class.getModule()
|
||||
* or null if data is not available.
|
||||
*
|
||||
* @return current version or null if missing version data
|
||||
* @since 2.0.14
|
||||
*/
|
||||
// static private String slf4jVersionByModule() {
|
||||
// Module module = Slf4jEnvUtil.class.getModule();
|
||||
// if (module == null)
|
||||
// return null;
|
||||
//
|
||||
// ModuleDescriptor md = module.getDescriptor();
|
||||
// if (md == null)
|
||||
// return null;
|
||||
// Optional<String> opt = md.rawVersion();
|
||||
// return opt.orElse(null);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -7,8 +7,18 @@ import org.slf4j.spi.SLF4JServiceProvider;
|
|||
|
||||
public class SubstituteServiceProvider implements SLF4JServiceProvider {
|
||||
private final SubstituteLoggerFactory loggerFactory = new SubstituteLoggerFactory();
|
||||
private final IMarkerFactory markerFactory = new BasicMarkerFactory();
|
||||
private final MDCAdapter mdcAdapter = new BasicMDCAdapter();
|
||||
|
||||
// LoggerFactory expects providers to initialize markerFactory as early as possible.
|
||||
private final IMarkerFactory markerFactory;
|
||||
|
||||
// LoggerFactory expects providers to initialize their MDCAdapter field
|
||||
// as early as possible, preferably at construction time.
|
||||
private final MDCAdapter mdcAdapter;
|
||||
|
||||
public SubstituteServiceProvider() {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new BasicMDCAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
|
|
@ -36,6 +46,5 @@ public class SubstituteServiceProvider implements SLF4JServiceProvider {
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,14 +117,28 @@ public final class Util {
|
|||
return trace[i + 2];
|
||||
}
|
||||
|
||||
// private static final void report(String msg, Throwable t) {
|
||||
// System.err.println(msg);
|
||||
// System.err.println("Reported exception:");
|
||||
// t.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// static final private void report(String msg) {
|
||||
// System.err.println("SLF4J: " + msg);
|
||||
// }
|
||||
/**
|
||||
* See {@link Reporter#error(String, Throwable)} class for alternative.
|
||||
*
|
||||
* @deprecated replaced by the {@link Reporter#error(String, Throwable)} method.
|
||||
* @param msg message to print
|
||||
* @param t throwable to print
|
||||
*/
|
||||
static final public void report(String msg, Throwable t) {
|
||||
System.err.println(msg);
|
||||
System.err.println("Reported exception:");
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link Reporter} class for alternatives.
|
||||
*
|
||||
* @deprecated replaced by one of {@link Reporter#info(String)},
|
||||
* {@link Reporter#warn(String)} or {@link Reporter#error(String)} methods.
|
||||
* @param msg message to print
|
||||
*/
|
||||
static final public void report(String msg) {
|
||||
System.err.println("SLF4J: " + msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2022 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
|
@ -9,10 +9,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
|
@ -20,10 +20,10 @@
|
|||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.spi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -38,11 +38,11 @@ import org.slf4j.event.LoggingEvent;
|
|||
*/
|
||||
public class DefaultLoggingEventBuilder implements LoggingEventBuilder, CallerBoundaryAware {
|
||||
|
||||
|
||||
|
||||
// The caller boundary when the log() methods are invoked, is this class itself.
|
||||
|
||||
|
||||
static String DLEB_FQCN = DefaultLoggingEventBuilder.class.getName();
|
||||
|
||||
|
||||
protected DefaultLoggingEvent loggingEvent;
|
||||
protected Logger logger;
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ public class DefaultLoggingEventBuilder implements LoggingEventBuilder, CallerBo
|
|||
|
||||
/**
|
||||
* Add a marker to the current logging event being built.
|
||||
*
|
||||
* <p>
|
||||
* It is possible to add multiple markers to the same logging event.
|
||||
*
|
||||
* @param marker the marker to add
|
||||
|
|
@ -72,165 +72,16 @@ public class DefaultLoggingEventBuilder implements LoggingEventBuilder, CallerBo
|
|||
|
||||
@Override
|
||||
public LoggingEventBuilder addArgument(Object p) {
|
||||
loggingEvent.addArgument(p);
|
||||
this.loggingEvent.addArgument(p);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggingEventBuilder addArgument(Supplier<?> objectSupplier) {
|
||||
loggingEvent.addArgument(objectSupplier.get());
|
||||
this.loggingEvent.addArgument(objectSupplier.get());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallerBoundary(String fqcn) {
|
||||
loggingEvent.setCallerBoundary(fqcn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
log(loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggingEventBuilder setMessage(String message) {
|
||||
loggingEvent.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public LoggingEventBuilder setMessage(Supplier<String> messageSupplier) {
|
||||
loggingEvent.setMessage(messageSupplier.get());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
loggingEvent.setMessage(message);
|
||||
log(loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object arg) {
|
||||
loggingEvent.setMessage(message);
|
||||
loggingEvent.addArgument(arg);
|
||||
log(loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object arg0, Object arg1) {
|
||||
loggingEvent.setMessage(message);
|
||||
loggingEvent.addArgument(arg0);
|
||||
loggingEvent.addArgument(arg1);
|
||||
log(loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object... args) {
|
||||
loggingEvent.setMessage(message);
|
||||
loggingEvent.addArguments(args);
|
||||
|
||||
log(loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Supplier<String> messageSupplier) {
|
||||
if (messageSupplier == null) {
|
||||
log((String) null);
|
||||
} else {
|
||||
log(messageSupplier.get());
|
||||
}
|
||||
}
|
||||
|
||||
protected void log(LoggingEvent aLoggingEvent) {
|
||||
setCallerBoundary(DLEB_FQCN);
|
||||
if (logger instanceof LoggingEventAware) {
|
||||
((LoggingEventAware) logger).log(aLoggingEvent);
|
||||
} else {
|
||||
logViaPublicSLF4JLoggerAPI(aLoggingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private void logViaPublicSLF4JLoggerAPI(LoggingEvent aLoggingEvent) {
|
||||
Object[] argArray = aLoggingEvent.getArgumentArray();
|
||||
int argLen = argArray == null ? 0 : argArray.length;
|
||||
|
||||
Throwable t = aLoggingEvent.getThrowable();
|
||||
int tLen = t == null ? 0 : 1;
|
||||
|
||||
String msg = aLoggingEvent.getMessage();
|
||||
|
||||
Object[] combinedArguments = new Object[argLen + tLen];
|
||||
|
||||
if (argArray != null) {
|
||||
System.arraycopy(argArray, 0, combinedArguments, 0, argLen);
|
||||
}
|
||||
if (t != null) {
|
||||
combinedArguments[argLen] = t;
|
||||
}
|
||||
|
||||
msg = mergeMarkersAndKeyValuePairs(aLoggingEvent, msg);
|
||||
|
||||
switch (aLoggingEvent.getLevel()) {
|
||||
case TRACE:
|
||||
logger.trace(msg, combinedArguments);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(msg, combinedArguments);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(msg, combinedArguments);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(msg, combinedArguments);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(msg, combinedArguments);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend markers and key-value pairs to the message.
|
||||
*
|
||||
* @param aLoggingEvent
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
private String mergeMarkersAndKeyValuePairs(LoggingEvent aLoggingEvent, String msg) {
|
||||
|
||||
StringBuilder sb = null;
|
||||
|
||||
if (aLoggingEvent.getMarkers() != null) {
|
||||
sb = new StringBuilder();
|
||||
for (Marker marker : aLoggingEvent.getMarkers()) {
|
||||
sb.append(marker);
|
||||
sb.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (aLoggingEvent.getKeyValuePairs() != null) {
|
||||
if (sb == null) {
|
||||
sb = new StringBuilder();
|
||||
}
|
||||
for (KeyValuePair kvp : aLoggingEvent.getKeyValuePairs()) {
|
||||
sb.append(kvp.key);
|
||||
sb.append('=');
|
||||
sb.append(kvp.value);
|
||||
sb.append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
if (sb != null) {
|
||||
sb.append(msg);
|
||||
return sb.toString();
|
||||
} else {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public LoggingEventBuilder addKeyValue(String key, Object value) {
|
||||
loggingEvent.addKeyValue(key, value);
|
||||
|
|
@ -243,4 +94,184 @@ public class DefaultLoggingEventBuilder implements LoggingEventBuilder, CallerBo
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCallerBoundary(String fqcn) {
|
||||
this.loggingEvent.setCallerBoundary(fqcn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
log(this.loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggingEventBuilder setMessage(String message) {
|
||||
this.loggingEvent.setMessage(message);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoggingEventBuilder setMessage(Supplier<String> messageSupplier) {
|
||||
this.loggingEvent.setMessage(messageSupplier.get());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message) {
|
||||
this.loggingEvent.setMessage(message);
|
||||
log(this.loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object arg) {
|
||||
this.loggingEvent.setMessage(message);
|
||||
this.loggingEvent.addArgument(arg);
|
||||
log(this.loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object arg0, Object arg1) {
|
||||
this.loggingEvent.setMessage(message);
|
||||
this.loggingEvent.addArgument(arg0);
|
||||
this.loggingEvent.addArgument(arg1);
|
||||
log(this.loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(String message, Object... args) {
|
||||
this.loggingEvent.setMessage(message);
|
||||
this.loggingEvent.addArguments(args);
|
||||
|
||||
log(this.loggingEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(Supplier<String> messageSupplier) {
|
||||
if(messageSupplier == null) {
|
||||
log((String) null);
|
||||
} else {
|
||||
log(messageSupplier.get());
|
||||
}
|
||||
}
|
||||
|
||||
protected void log(LoggingEvent aLoggingEvent) {
|
||||
if(aLoggingEvent.getCallerBoundary() == null) {
|
||||
setCallerBoundary(DLEB_FQCN);
|
||||
}
|
||||
|
||||
if(logger instanceof LoggingEventAware) {
|
||||
((LoggingEventAware) logger).log(aLoggingEvent);
|
||||
} else if(logger instanceof LocationAwareLogger) {
|
||||
logViaLocationAwareLoggerAPI((LocationAwareLogger) logger, aLoggingEvent);
|
||||
} else {
|
||||
logViaPublicSLF4JLoggerAPI(aLoggingEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private void logViaLocationAwareLoggerAPI(LocationAwareLogger locationAwareLogger, LoggingEvent aLoggingEvent) {
|
||||
List<Marker> markerList = aLoggingEvent.getMarkers();
|
||||
Marker firstMarker = (markerList != null && !markerList.isEmpty()) ? markerList.get(0) : null;
|
||||
String mergedMessage = mergeMarkersAndKeyValuePairsAndMessage(aLoggingEvent);
|
||||
locationAwareLogger.log(firstMarker, aLoggingEvent.getCallerBoundary(), aLoggingEvent.getLevel().toInt(),
|
||||
mergedMessage,
|
||||
aLoggingEvent.getArgumentArray(), aLoggingEvent.getThrowable());
|
||||
}
|
||||
|
||||
private void logViaPublicSLF4JLoggerAPI(LoggingEvent aLoggingEvent) {
|
||||
Object[] argArray = aLoggingEvent.getArgumentArray();
|
||||
int argLen = argArray == null ? 0 : argArray.length;
|
||||
|
||||
Throwable t = aLoggingEvent.getThrowable();
|
||||
int tLen = t == null ? 0 : 1;
|
||||
|
||||
Object[] combinedArguments = new Object[argLen + tLen];
|
||||
|
||||
if(argArray != null) {
|
||||
System.arraycopy(argArray, 0, combinedArguments, 0, argLen);
|
||||
}
|
||||
if(t != null) {
|
||||
combinedArguments[argLen] = t;
|
||||
}
|
||||
|
||||
String mergedMessage = mergeMarkersAndKeyValuePairsAndMessage(aLoggingEvent);
|
||||
|
||||
|
||||
switch(aLoggingEvent.getLevel()) {
|
||||
case TRACE:
|
||||
logger.trace(mergedMessage, combinedArguments);
|
||||
break;
|
||||
case DEBUG:
|
||||
logger.debug(mergedMessage, combinedArguments);
|
||||
break;
|
||||
case INFO:
|
||||
logger.info(mergedMessage, combinedArguments);
|
||||
break;
|
||||
case WARN:
|
||||
logger.warn(mergedMessage, combinedArguments);
|
||||
break;
|
||||
case ERROR:
|
||||
logger.error(mergedMessage, combinedArguments);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepend markers and key-value pairs to the message.
|
||||
*
|
||||
* @param aLoggingEvent
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String mergeMarkersAndKeyValuePairsAndMessage(LoggingEvent aLoggingEvent) {
|
||||
StringBuilder sb = mergeMarkers(aLoggingEvent.getMarkers(), null);
|
||||
sb = mergeKeyValuePairs(aLoggingEvent.getKeyValuePairs(), sb);
|
||||
final String mergedMessage = mergeMessage(aLoggingEvent.getMessage(), sb);
|
||||
return mergedMessage;
|
||||
}
|
||||
|
||||
private StringBuilder mergeMarkers(List<Marker> markerList, StringBuilder sb) {
|
||||
if(markerList == null || markerList.isEmpty())
|
||||
return sb;
|
||||
|
||||
if(sb == null)
|
||||
sb = new StringBuilder();
|
||||
|
||||
for(Marker marker : markerList) {
|
||||
sb.append(marker);
|
||||
sb.append(' ');
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
private StringBuilder mergeKeyValuePairs(List<KeyValuePair> keyValuePairList, StringBuilder sb) {
|
||||
if(keyValuePairList == null || keyValuePairList.isEmpty())
|
||||
return sb;
|
||||
|
||||
if(sb == null)
|
||||
sb = new StringBuilder();
|
||||
|
||||
for(KeyValuePair kvp : keyValuePairList) {
|
||||
sb.append(kvp.key);
|
||||
sb.append('=');
|
||||
sb.append(kvp.value);
|
||||
sb.append(' ');
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
private String mergeMessage(String msg, StringBuilder sb) {
|
||||
if(sb != null) {
|
||||
sb.append(msg);
|
||||
return sb.toString();
|
||||
} else {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public interface MDCAdapter {
|
|||
public void setContextMap(Map<String, String> contextMap);
|
||||
|
||||
/**
|
||||
* Push a value into the deque(stack) referenced by 'key'.
|
||||
* Push a value into the <b>deque(stack)</b> referenced by 'key'.
|
||||
*
|
||||
* @param key identifies the appropriate stack
|
||||
* @param value the value to push into the stack
|
||||
|
|
@ -102,7 +102,7 @@ public interface MDCAdapter {
|
|||
public void pushByKey(String key, String value);
|
||||
|
||||
/**
|
||||
* Pop the stack referenced by 'key' and return the value possibly null.
|
||||
* Pop the <b>stack</b> referenced by 'key' and return the value possibly null.
|
||||
*
|
||||
* @param key identifies the deque(stack)
|
||||
* @return the value just popped. May be null/
|
||||
|
|
@ -111,7 +111,7 @@ public interface MDCAdapter {
|
|||
public String popByKey(String key);
|
||||
|
||||
/**
|
||||
* Returns a copy of the deque(stack) referenced by 'key'. May be null.
|
||||
* Returns a copy of the <b>deque(stack)</b> referenced by 'key'. May be null.
|
||||
*
|
||||
* @param key identifies the stack
|
||||
* @return copy of stack referenced by 'key'. May be null.
|
||||
|
|
@ -122,7 +122,7 @@ public interface MDCAdapter {
|
|||
|
||||
|
||||
/**
|
||||
* Clear the deque(stack) referenced by 'key'.
|
||||
* Clear the <b>deque(stack)</b> referenced by 'key'.
|
||||
*
|
||||
* @param key identifies the stack
|
||||
*
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -37,11 +39,21 @@ import org.slf4j.Marker;
|
|||
import org.slf4j.MarkerFactory;
|
||||
import org.slf4j.helpers.BasicMarker;
|
||||
import org.slf4j.helpers.NOPLogger;
|
||||
import org.slf4j.helpers.Reporter;
|
||||
|
||||
public class NoBindingTest {
|
||||
|
||||
int diff = new Random().nextInt(10000);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.setProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY, "debug");
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.clearProperty(Reporter.SLF4J_INTERNAL_VERBOSITY_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogger() {
|
||||
Logger logger = LoggerFactory.getLogger(NoBindingTest.class);
|
||||
|
|
|
|||
|
|
@ -36,16 +36,15 @@ abstract public class MultithreadedInitializationTest {
|
|||
|
||||
assertAllSubstLoggersAreFixed();
|
||||
long recordedEventCount = getRecordedEventCount();
|
||||
int LENIENCY_COUNT = 21;
|
||||
int LENIENCY_COUNT = 30;
|
||||
|
||||
long expectedEventCount = eventCount.get() + extraLogEvents();
|
||||
|
||||
assertTrue(expectedEventCount + " >= " + recordedEventCount, expectedEventCount >= recordedEventCount);
|
||||
assertTrue(expectedEventCount + " < " + recordedEventCount + "+" + LENIENCY_COUNT, expectedEventCount < recordedEventCount + LENIENCY_COUNT);
|
||||
}
|
||||
assertTrue("unmet condition: " + expectedEventCount + " >= " + recordedEventCount, expectedEventCount >= recordedEventCount);
|
||||
assertTrue("unmet condition: " + expectedEventCount + " < " + recordedEventCount + "+" + LENIENCY_COUNT, expectedEventCount < (recordedEventCount + LENIENCY_COUNT)); }
|
||||
|
||||
abstract protected long getRecordedEventCount();
|
||||
|
||||
|
||||
protected int extraLogEvents() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<parent>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -115,16 +115,11 @@ class SLF4JPlatformLogger implements System.Logger {
|
|||
* @param thrown
|
||||
* @param params
|
||||
*/
|
||||
private void log(Level jplLevel, ResourceBundle bundle, String msg, Throwable thrown, Object... params) {
|
||||
if (jplLevel == Level.OFF)
|
||||
return;
|
||||
private void log(final Level jplLevel, final ResourceBundle bundle, final String msg, final Throwable thrown, final Object... params) {
|
||||
|
||||
if (jplLevel == Level.ALL) {
|
||||
performLog(org.slf4j.event.Level.TRACE, bundle, msg, thrown, params);
|
||||
return;
|
||||
}
|
||||
final Level jplLevelReduced = fixExtremeLevels(jplLevel);
|
||||
|
||||
org.slf4j.event.Level slf4jLevel = jplLevelToSLF4JLevel(jplLevel);
|
||||
org.slf4j.event.Level slf4jLevel = jplLevelToSLF4JLevel(jplLevelReduced);
|
||||
boolean isEnabled = slf4jLogger.isEnabledForLevel(slf4jLevel);
|
||||
|
||||
if (isEnabled) {
|
||||
|
|
@ -132,6 +127,27 @@ class SLF4JPlatformLogger implements System.Logger {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Level.OFF and Level.ALL levels are not supposed to be used when calling log printing methods.
|
||||
* </p>
|
||||
*
|
||||
* <p>We compensate for such incorrect usage by transforming Level.OFF as Level.ERROR and
|
||||
* Level.ALL as Level.TRACE.
|
||||
* </p>
|
||||
*
|
||||
* @param jplLevel
|
||||
* @return
|
||||
*/
|
||||
private Level fixExtremeLevels(Level jplLevel) {
|
||||
if (jplLevel == Level.OFF)
|
||||
return Level.ERROR;
|
||||
|
||||
if (jplLevel == Level.ALL)
|
||||
return Level.TRACE;
|
||||
|
||||
return jplLevel;
|
||||
}
|
||||
|
||||
private void performLog(org.slf4j.event.Level slf4jLevel, ResourceBundle bundle, String msg, Throwable thrown, Object... params) {
|
||||
String message = getResourceStringOrMessage(bundle, msg);
|
||||
LoggingEventBuilder leb = slf4jLogger.makeLoggingEventBuilder(slf4jLevel);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.junit.After;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The present test is fragile in the sense that it sets up SimpleLogger
|
||||
|
|
@ -108,12 +109,27 @@ public class SLF4JPlatformLoggingTest {
|
|||
//INFO throwTest - a problem
|
||||
//java.lang.Exception
|
||||
// at org.slf4j.jdk.platform.logging/org.slf4j.jdk.platform.logging.SLF4JPlatformLoggingTest.throwTest(SLF4JPlatformLoggingTest.java:92)
|
||||
|
||||
assertEquals("INFO throwTest - we have a problem", results.get(0));
|
||||
assertEquals(Exception.class.getName(), results.get(1));
|
||||
assertTrue(results.get(2).contains("at "));
|
||||
assertTrue(results.get(2).contains(this.getClass().getName()));
|
||||
|
||||
int line = 0;
|
||||
//assertTrue(results.get(0).startsWith("SLF4J(I): Connected with provider of type ["));
|
||||
assertEquals("INFO throwTest - we have a problem", results.get(line++));
|
||||
assertEquals(Exception.class.getName(), results.get(line++));
|
||||
assertTrue(results.get(line).contains("at "));
|
||||
assertTrue(results.get(line++).contains(this.getClass().getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extremeLevels() throws IOException {
|
||||
LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
|
||||
assertEquals(EXPECTED_FINDER_CLASS, finder.getClass().getName());
|
||||
Logger systemLogger = finder.getLogger("extremeLevels", null);
|
||||
systemLogger.log(Level.OFF, "hello");
|
||||
systemLogger.log(Level.ALL, "world");
|
||||
|
||||
List<String> results = SPS.stringList;
|
||||
assertEquals(1, results.size());
|
||||
assertEquals("ERROR extremeLevels - hello", results.get(0));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ public final class JDK14LoggerAdapter extends LegacyAbstractLogger implements Lo
|
|||
|
||||
transient final java.util.logging.Logger logger;
|
||||
|
||||
static int NOT_FOUND = -1;
|
||||
|
||||
// WARN: JDK14LoggerAdapter constructor should have only package access so
|
||||
// that only JDK14LoggerFactory be able to create one.
|
||||
JDK14LoggerAdapter(java.util.logging.Logger logger) {
|
||||
|
|
@ -181,26 +183,10 @@ public final class JDK14LoggerAdapter extends LegacyAbstractLogger implements Lo
|
|||
final private void fillCallerData(String callerFQCN, LogRecord record) {
|
||||
StackTraceElement[] steArray = new Throwable().getStackTrace();
|
||||
|
||||
int selfIndex = -1;
|
||||
for (int i = 0; i < steArray.length; i++) {
|
||||
final String className = steArray[i].getClassName();
|
||||
int furthestIndex = findFurthestIndex(callerFQCN, steArray);
|
||||
|
||||
if (barrierMatch(callerFQCN, className)) {
|
||||
selfIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int found = -1;
|
||||
for (int i = selfIndex + 1; i < steArray.length; i++) {
|
||||
final String className = steArray[i].getClassName();
|
||||
if (!(barrierMatch(callerFQCN, className))) {
|
||||
found = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found != -1) {
|
||||
if (furthestIndex != NOT_FOUND) {
|
||||
int found = furthestIndex+1;
|
||||
StackTraceElement ste = steArray[found];
|
||||
// setting the class name has the side effect of setting
|
||||
// the needToInferCaller variable to false.
|
||||
|
|
@ -209,7 +195,24 @@ public final class JDK14LoggerAdapter extends LegacyAbstractLogger implements Lo
|
|||
}
|
||||
}
|
||||
|
||||
static String SELF = JDK14LoggerAdapter.class.getName();
|
||||
// find the furthest index which matches any of the barrier classes
|
||||
// We assume that the actual caller is at most MAX_SEARCH_DEPTH calls away
|
||||
private int findFurthestIndex(String callerFQCN, StackTraceElement[] steArray) {
|
||||
|
||||
final int maxIndex = Math.min(MAX_SEARCH_DEPTH, steArray.length);
|
||||
int furthestIndex = NOT_FOUND;
|
||||
|
||||
for (int i = 0; i < maxIndex; i++) {
|
||||
final String className = steArray[i].getClassName();
|
||||
if (barrierMatch(callerFQCN, className)) {
|
||||
furthestIndex = i;
|
||||
}
|
||||
}
|
||||
return furthestIndex;
|
||||
}
|
||||
|
||||
static final int MAX_SEARCH_DEPTH = 12;
|
||||
static String SELF = JDK14LoggerAdapter.class.getName();
|
||||
|
||||
static String SUPER = LegacyAbstractLogger.class.getName();
|
||||
static String SUPER_OF_SUPER = AbstractLogger.class.getName();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,16 @@ public class JULServiceProvider implements SLF4JServiceProvider {
|
|||
public static String REQUESTED_API_VERSION = "2.0.99"; // !final
|
||||
|
||||
private ILoggerFactory loggerFactory;
|
||||
private IMarkerFactory markerFactory;
|
||||
private MDCAdapter mdcAdapter;
|
||||
// LoggerFactory expects providers to initialize markerFactory as early as possible.
|
||||
private final IMarkerFactory markerFactory;
|
||||
// LoggerFactory expects providers to initialize their MDCAdapter field
|
||||
// as early as possible, preferably at construction time.
|
||||
private final MDCAdapter mdcAdapter;
|
||||
|
||||
public JULServiceProvider() {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new BasicMDCAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
|
|
@ -42,7 +50,5 @@ public class JULServiceProvider implements SLF4JServiceProvider {
|
|||
@Override
|
||||
public void initialize() {
|
||||
loggerFactory = new JDK14LoggerFactory();
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new BasicMDCAdapter();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,8 @@ module org.slf4j.jul {
|
|||
requires org.slf4j;
|
||||
requires java.logging;
|
||||
provides org.slf4j.spi.SLF4JServiceProvider with org.slf4j.jul.JULServiceProvider;
|
||||
|
||||
exports org.slf4j.jul;
|
||||
opens org.slf4j.jul to org.slf4j;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import org.slf4j.event.SubstituteLoggingEvent;
|
|||
import org.slf4j.helpers.SubstituteLogger;
|
||||
import org.slf4j.helpers.SubstituteServiceProvider;
|
||||
import org.slf4j.jul.ListHandler;
|
||||
import org.slf4j.spi.CallerBoundaryAware;
|
||||
import org.slf4j.spi.LoggingEventBuilder;
|
||||
|
||||
public class CallerInfoTest {
|
||||
Level oldLevel;
|
||||
|
|
@ -77,6 +79,22 @@ public class CallerInfoTest {
|
|||
assertEquals(this.getClass().getName(), logRecod.getSourceClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallerInfoWithFluentAPIAndAWrapper() {
|
||||
Logger logger = LoggerFactory.getLogger("bla");
|
||||
LoggingWrapper wrappedLogger = new LoggingWrapper(logger);
|
||||
|
||||
wrappedLogger.logWithEvent("hello");
|
||||
|
||||
List<LogRecord> recordList = listHandler.recordList;
|
||||
|
||||
assertEquals(1, recordList.size());
|
||||
|
||||
LogRecord logRecod = recordList.get(0);
|
||||
assertEquals(this.getClass().getName(), logRecod.getSourceClassName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPostInitializationCallerInfoWithSubstituteLogger() {
|
||||
Logger logger = LoggerFactory.getLogger("bla");
|
||||
|
|
@ -119,4 +137,22 @@ public class CallerInfoTest {
|
|||
assertEquals(EventConstants.NA_SUBST, logRecod.getSourceClassName());
|
||||
}
|
||||
|
||||
static class LoggingWrapper {
|
||||
|
||||
Logger underlyingLogger;
|
||||
|
||||
LoggingWrapper(Logger aLogger) {
|
||||
this.underlyingLogger = aLogger;
|
||||
}
|
||||
public void logWithEvent(String msg) {
|
||||
LoggingEventBuilder lev = underlyingLogger.atInfo();
|
||||
// setting the caller boundary to LoggingWrapper
|
||||
if(lev instanceof CallerBoundaryAware) {
|
||||
// builder is CallerBoundaryAware
|
||||
((CallerBoundaryAware) lev).setCallerBoundary(LoggingWrapper.class.getName());
|
||||
}
|
||||
lev.log(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
<relocation>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-reload4j</artifactId>
|
||||
<version>2.0.9</version>
|
||||
<version>2.0.18</version>
|
||||
</relocation>
|
||||
</distributionManagement>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -29,6 +29,14 @@
|
|||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<type>test-jar</type>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -18,9 +18,18 @@ public class NOPServiceProvider implements SLF4JServiceProvider {
|
|||
public static String REQUESTED_API_VERSION = "2.0.99"; // !final
|
||||
|
||||
private final ILoggerFactory loggerFactory = new NOPLoggerFactory();
|
||||
private final IMarkerFactory markerFactory = new BasicMarkerFactory();
|
||||
private final MDCAdapter mdcAdapter = new NOPMDCAdapter();
|
||||
|
||||
// LoggerFactory expects providers to initialize markerFactory as early as possible.
|
||||
private final IMarkerFactory markerFactory;
|
||||
|
||||
// LoggerFactory expects providers to initialize their MDCAdapter field
|
||||
// as early as possible, preferably at construction time.
|
||||
private final MDCAdapter mdcAdapter;
|
||||
|
||||
public NOPServiceProvider() {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
}
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
return loggerFactory;
|
||||
}
|
||||
|
|
@ -39,7 +48,6 @@ public class NOPServiceProvider implements SLF4JServiceProvider {
|
|||
}
|
||||
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
module org.slf4j.nop {
|
||||
requires org.slf4j;
|
||||
provides org.slf4j.spi.SLF4JServiceProvider with org.slf4j.nop.NOPServiceProvider;
|
||||
|
||||
exports org.slf4j.nop;
|
||||
opens org.slf4j.nop to org.slf4j;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (c) 2004-2016 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
|
@ -9,10 +9,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* <p>
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* <p>
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
|
|
@ -20,29 +20,29 @@
|
|||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
package org.slf4j.nop;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.LoggerFactoryFriend;
|
||||
import org.slf4j.helpers.StringPrintStream;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.slf4j.helpers.Reporter.SLF4J_INTERNAL_VERBOSITY_KEY;
|
||||
|
||||
public class MultithreadedInitializationTest {
|
||||
|
||||
static int NUM_LINES_IN_SLF4J_CONNECTED_WITH_PROVIDER_INFO = 1;
|
||||
final static int THREAD_COUNT = 4 + Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
private static final AtomicLong EVENT_COUNT = new AtomicLong(0);
|
||||
|
|
@ -52,16 +52,18 @@ public class MultithreadedInitializationTest {
|
|||
int diff = new Random().nextInt(10000);
|
||||
String loggerName = "org.slf4j.impl.MultithreadedInitializationTest";
|
||||
private final PrintStream oldErr = System.err;
|
||||
StringPrintStream sps = new StringPrintStream(oldErr);
|
||||
StringPrintStream sps = new StringPrintStream(oldErr, false);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
System.setProperty(SLF4J_INTERNAL_VERBOSITY_KEY, "debug");
|
||||
LoggerFactoryFriend.reset();
|
||||
System.setErr(sps);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.clearProperty(SLF4J_INTERNAL_VERBOSITY_KEY);
|
||||
LoggerFactoryFriend.reset();
|
||||
System.setErr(oldErr);
|
||||
}
|
||||
|
|
@ -71,7 +73,7 @@ public class MultithreadedInitializationTest {
|
|||
System.out.println("THREAD_COUNT=" + THREAD_COUNT);
|
||||
LoggerAccessingThread[] accessors = harness();
|
||||
|
||||
for (LoggerAccessingThread accessor : accessors) {
|
||||
for(LoggerAccessingThread accessor : accessors) {
|
||||
EVENT_COUNT.getAndIncrement();
|
||||
accessor.logger.info("post harness");
|
||||
}
|
||||
|
|
@ -80,19 +82,19 @@ public class MultithreadedInitializationTest {
|
|||
logger.info("hello");
|
||||
EVENT_COUNT.getAndIncrement();
|
||||
|
||||
assertEquals(0, sps.stringList.size());
|
||||
assertEquals(NUM_LINES_IN_SLF4J_CONNECTED_WITH_PROVIDER_INFO, sps.stringList.size());
|
||||
}
|
||||
|
||||
private static LoggerAccessingThread[] harness() throws InterruptedException, BrokenBarrierException {
|
||||
LoggerAccessingThread[] threads = new LoggerAccessingThread[THREAD_COUNT];
|
||||
final CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT + 1);
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
for(int i = 0; i < THREAD_COUNT; i++) {
|
||||
threads[i] = new LoggerAccessingThread(barrier, i);
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
barrier.await();
|
||||
for (int i = 0; i < THREAD_COUNT; i++) {
|
||||
for(int i = 0; i < THREAD_COUNT; i++) {
|
||||
threads[i].join();
|
||||
}
|
||||
return threads;
|
||||
|
|
@ -118,33 +120,35 @@ public class MultithreadedInitializationTest {
|
|||
logger.info("in run method");
|
||||
EVENT_COUNT.getAndIncrement();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class StringPrintStream extends PrintStream {
|
||||
;
|
||||
|
||||
public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
PrintStream other;
|
||||
List<String> stringList = new ArrayList<>();
|
||||
|
||||
public StringPrintStream(PrintStream ps) {
|
||||
super(ps);
|
||||
other = ps;
|
||||
}
|
||||
|
||||
public void print(String s) {
|
||||
other.print(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
|
||||
public void println(String s) {
|
||||
other.println(s);
|
||||
stringList.add(s);
|
||||
}
|
||||
|
||||
public void println(Object o) {
|
||||
other.println(o);
|
||||
stringList.add(o.toString());
|
||||
}
|
||||
};
|
||||
// public static class StringPrintStream extends PrintStream {
|
||||
//
|
||||
// public static final String LINE_SEP = System.getProperty("line.separator");
|
||||
// PrintStream other;
|
||||
// List<String> stringList = new ArrayList<>();
|
||||
//
|
||||
// public StringPrintStream(PrintStream ps) {
|
||||
// super(ps);
|
||||
// other = ps;
|
||||
// }
|
||||
//
|
||||
// public void print(String s) {
|
||||
// other.print(s);
|
||||
// stringList.add(s);
|
||||
// }
|
||||
//
|
||||
// public void println(String s) {
|
||||
// other.println(s);
|
||||
// stringList.add(s);
|
||||
// }
|
||||
//
|
||||
// public void println(Object o) {
|
||||
// other.println(o);
|
||||
// stringList.add(o.toString());
|
||||
// }
|
||||
// };
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
@ -51,7 +51,6 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>false</reuseForks>
|
||||
|
|
@ -61,7 +60,7 @@
|
|||
<exclude>**/AllTest.java</exclude>
|
||||
<exclude>**/PackageTest.java</exclude>
|
||||
</excludes>
|
||||
<argLine>-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001</argLine>
|
||||
<!--<argLine>-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8001</argLine> -->
|
||||
<!--<argLine>XXadd-opens log4j/org.apache.log4j=org.slf4j.log4j12</argLine>-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
|||
|
|
@ -19,10 +19,17 @@ public class Reload4jServiceProvider implements SLF4JServiceProvider {
|
|||
public static String REQUESTED_API_VERSION = "2.0.99"; // !final
|
||||
|
||||
private ILoggerFactory loggerFactory;
|
||||
private IMarkerFactory markerFactory;
|
||||
private MDCAdapter mdcAdapter;
|
||||
|
||||
// LoggerFactory expects providers to initialize markerFactory as early as possible.
|
||||
private final IMarkerFactory markerFactory;
|
||||
|
||||
// LoggerFactory expects providers to have a valid MDCAdapter field
|
||||
// as early as possible, preferably at construction time.
|
||||
private final MDCAdapter mdcAdapter;
|
||||
|
||||
public Reload4jServiceProvider() {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new Reload4jMDCAdapter();
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
Level level = Level.TRACE;
|
||||
|
|
@ -34,8 +41,6 @@ public class Reload4jServiceProvider implements SLF4JServiceProvider {
|
|||
@Override
|
||||
public void initialize() {
|
||||
loggerFactory = new Reload4jLoggerFactory();
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new Reload4jMDCAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>2.0.10-SNAPSHOT</version>
|
||||
<version>2.0.19-SNAPSHOT</version>
|
||||
<relativePath>../parent/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -221,10 +221,10 @@ public class SimpleLogger extends LegacyAbstractLogger {
|
|||
public static final String DEFAULT_LOG_LEVEL_KEY = SimpleLogger.SYSTEM_PREFIX + "defaultLogLevel";
|
||||
|
||||
/**
|
||||
* Package access allows only {@link SimpleLoggerFactory} to instantiate
|
||||
* Protected access allows only {@link SimpleLoggerFactory} and also derived classes to instantiate
|
||||
* SimpleLogger instances.
|
||||
*/
|
||||
SimpleLogger(String name) {
|
||||
protected SimpleLogger(String name) {
|
||||
this.name = name;
|
||||
|
||||
String levelString = recursivelyComputeLevelString();
|
||||
|
|
@ -409,7 +409,7 @@ public class SimpleLogger extends LegacyAbstractLogger {
|
|||
buf.append('[');
|
||||
|
||||
// Append a readable representation of the log level
|
||||
String levelStr = level.name();
|
||||
String levelStr = renderLevel(level.toInt());
|
||||
buf.append(levelStr);
|
||||
if (CONFIG_PARAMS.levelInBrackets)
|
||||
buf.append(']');
|
||||
|
|
@ -439,6 +439,22 @@ public class SimpleLogger extends LegacyAbstractLogger {
|
|||
write(buf, t);
|
||||
}
|
||||
|
||||
protected String renderLevel(int levelInt) {
|
||||
switch (levelInt) {
|
||||
case LOG_LEVEL_TRACE:
|
||||
return "TRACE";
|
||||
case LOG_LEVEL_DEBUG:
|
||||
return("DEBUG");
|
||||
case LOG_LEVEL_INFO:
|
||||
return "INFO";
|
||||
case LOG_LEVEL_WARN:
|
||||
return CONFIG_PARAMS.warnLevelString;
|
||||
case LOG_LEVEL_ERROR:
|
||||
return "ERROR";
|
||||
}
|
||||
throw new IllegalStateException("Unrecognized level ["+levelInt+"]");
|
||||
}
|
||||
|
||||
public void log(LoggingEvent event) {
|
||||
int levelInt = event.getLevel().toInt();
|
||||
|
||||
|
|
|
|||
|
|
@ -47,28 +47,31 @@ public class SimpleLoggerFactory implements ILoggerFactory {
|
|||
|
||||
/**
|
||||
* Return an appropriate {@link SimpleLogger} instance by name.
|
||||
*
|
||||
* This method will call {@link #createLogger(String)} if the logger
|
||||
* has not been created yet.
|
||||
*/
|
||||
public Logger getLogger(String name) {
|
||||
Logger simpleLogger = loggerMap.get(name);
|
||||
if (simpleLogger != null) {
|
||||
return simpleLogger;
|
||||
} else {
|
||||
Logger newInstance = new SimpleLogger(name);
|
||||
Logger oldInstance = loggerMap.putIfAbsent(name, newInstance);
|
||||
return oldInstance == null ? newInstance : oldInstance;
|
||||
}
|
||||
return loggerMap.computeIfAbsent(name, this::createLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually creates the logger for the given name.
|
||||
*/
|
||||
protected Logger createLogger(String name) {
|
||||
return new SimpleLogger(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the internal logger cache.
|
||||
*
|
||||
* This method is intended to be called by classes (in the same package) for
|
||||
* testing purposes. This method is internal. It can be modified, renamed or
|
||||
* removed at any time without notice.
|
||||
* This method is intended to be called by classes (in the same package or
|
||||
* subclasses) for testing purposes. This method is internal. It can be
|
||||
* modified, renamed or removed at any time without notice.
|
||||
*
|
||||
* You are strongly discouraged from calling this method in production code.
|
||||
*/
|
||||
void reset() {
|
||||
protected void reset() {
|
||||
loggerMap.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,16 @@ public class SimpleServiceProvider implements SLF4JServiceProvider {
|
|||
public static String REQUESTED_API_VERSION = "2.0.99"; // !final
|
||||
|
||||
private ILoggerFactory loggerFactory;
|
||||
private IMarkerFactory markerFactory;
|
||||
private MDCAdapter mdcAdapter;
|
||||
// LoggerFactory expects providers to initialize markerFactory as early as possible.
|
||||
private final IMarkerFactory markerFactory;
|
||||
// LoggerFactory expects providers to initialize their MDCAdapter field
|
||||
// as early as possible, preferably at construction time.
|
||||
private final MDCAdapter mdcAdapter;
|
||||
|
||||
public SimpleServiceProvider() {
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
}
|
||||
|
||||
public ILoggerFactory getLoggerFactory() {
|
||||
return loggerFactory;
|
||||
|
|
@ -41,10 +49,8 @@ public class SimpleServiceProvider implements SLF4JServiceProvider {
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
loggerFactory = new SimpleLoggerFactory();
|
||||
markerFactory = new BasicMarkerFactory();
|
||||
mdcAdapter = new NOPMDCAdapter();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
module org.slf4j.simple {
|
||||
module org.slf4j.simple {
|
||||
requires org.slf4j;
|
||||
provides org.slf4j.spi.SLF4JServiceProvider with org.slf4j.simple.SimpleServiceProvider;
|
||||
exports org.slf4j.simple;
|
||||
opens org.slf4j.simple to org.slf4j;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package org.slf4j.simple;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
@Ignore
|
||||
public class AcceptanceTest extends LoggerTestSuite {
|
||||
|
||||
@Override
|
||||
public Logger createLogger(ListAppendingOutputStream outputStream, Level level) {
|
||||
SimpleLogger.CONFIG_PARAMS.outputChoice = new OutputChoice(new PrintStream(outputStream));
|
||||
|
||||
SimpleLogger logger = new SimpleLogger("TestSuiteLogger");
|
||||
logger.currentLogLevel = SimpleLoggerConfiguration.stringToLevel(level.toString());
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractMessage(String message) {
|
||||
return message
|
||||
.split("\n")[0]
|
||||
.split("- ")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractExceptionMessage(String message) {
|
||||
String[] logLines = message.split("\n");
|
||||
|
||||
if (logLines.length < 2) {
|
||||
return null;
|
||||
}
|
||||
String exceptionLine = logLines[1];
|
||||
return exceptionLine.split(": ")[1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String extractExceptionType(String message) {
|
||||
String[] logLines = message.split("\n");
|
||||
|
||||
if (logLines.length < 2) {
|
||||
return null;
|
||||
}
|
||||
String exceptionLine = logLines[1];
|
||||
return exceptionLine.split(": ")[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package org.slf4j.simple;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test class to verify configuration parameters of SimpleLogger
|
||||
*
|
||||
* @since 2.0.18
|
||||
*/
|
||||
public class ConfigParamsTest {
|
||||
|
||||
|
||||
private ListAppendingOutputStream prepareSink(List<String> outputList) {
|
||||
return new ListAppendingOutputStream(outputList);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
static public void resetConfigParams() {
|
||||
SimpleLogger.CONFIG_PARAMS.init();
|
||||
}
|
||||
|
||||
public Logger createLogger(ListAppendingOutputStream outputStream, Level level, String warnLevelString) {
|
||||
SimpleLogger.CONFIG_PARAMS.outputChoice = new OutputChoice(new PrintStream(outputStream));
|
||||
|
||||
SimpleLogger.CONFIG_PARAMS.warnLevelString = warnLevelString;
|
||||
|
||||
SimpleLogger logger = new SimpleLogger(ConfigParamsTest.class.getName());
|
||||
logger.currentLogLevel = SimpleLoggerConfiguration.stringToLevel(level.toString());
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest(){
|
||||
String WARN_LEVEL_STRING = "WXYZ";
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.TRACE, WARN_LEVEL_STRING);
|
||||
|
||||
configuredLogger.warn("This is a test");
|
||||
|
||||
String str0 = outputList.get(0);
|
||||
assertTrue(str0.contains(WARN_LEVEL_STRING));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.slf4j.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class ListAppendingOutputStream extends OutputStream {
|
||||
|
||||
private final StringBuilder stringBuilder = new StringBuilder();
|
||||
private final List<String> targetList;
|
||||
|
||||
ListAppendingOutputStream(List<String> list) {this.targetList = list;}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
stringBuilder.append((char) b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
targetList.add(stringBuilder.toString());
|
||||
stringBuilder.delete(0, stringBuilder.length());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
package org.slf4j.simple;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public abstract class LoggerTestSuite {
|
||||
|
||||
private ListAppendingOutputStream prepareSink(List<String> outputList) {
|
||||
return new ListAppendingOutputStream(outputList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTrace() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.TRACE);
|
||||
|
||||
assertTrue("Trace level should be enabled for this test", configuredLogger.isTraceEnabled());
|
||||
configuredLogger.trace("Simple trace message");
|
||||
|
||||
assertEquals("Trace message should've been captured", 1, outputList.size());
|
||||
assertTrue("Message should be logged in trace level", isTraceMessage(outputList.get(0)));
|
||||
assertEquals("Supplied trace message wasn't found in the log",
|
||||
"Simple trace message",
|
||||
extractMessage(outputList.get(0)));
|
||||
|
||||
outputList.clear();
|
||||
|
||||
configuredLogger.debug("Simple debug message");
|
||||
configuredLogger.info("Simple info message");
|
||||
configuredLogger.warn("Simple warn message");
|
||||
configuredLogger.error("Simple error message");
|
||||
assertEquals("The other levels should have been captured", 4, outputList.size());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDebug() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.DEBUG);
|
||||
|
||||
configuredLogger.trace("Simple trace message");
|
||||
assertEquals("Lower levels should have been ignored", 0, outputList.size());
|
||||
|
||||
assertTrue("Debug level should be enabled for this test", configuredLogger.isDebugEnabled());
|
||||
configuredLogger.debug("Simple debug message");
|
||||
|
||||
assertEquals("Debug message should've been captured", 1, outputList.size());
|
||||
assertTrue("Message should be logged in debug level", isDebugMessage(outputList.get(0)));
|
||||
assertEquals("Supplied debug message wasn't found in the log",
|
||||
"Simple debug message",
|
||||
extractMessage(outputList.get(0)));
|
||||
|
||||
outputList.clear();
|
||||
|
||||
configuredLogger.info("Simple info message");
|
||||
configuredLogger.warn("Simple warn message");
|
||||
configuredLogger.error("Simple error message");
|
||||
assertEquals("The other levels should have been captured", 3, outputList.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInfo() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.INFO);
|
||||
|
||||
configuredLogger.trace("Simple trace message");
|
||||
configuredLogger.debug("Simple debug message");
|
||||
assertEquals("Lower levels should have been ignored", 0, outputList.size());
|
||||
|
||||
assertTrue("Info level should be enabled for this test", configuredLogger.isInfoEnabled());
|
||||
configuredLogger.info("Simple info message");
|
||||
|
||||
assertEquals("Info message should've been captured", 1, outputList.size());
|
||||
assertTrue("Message should be logged in debug level", isInfoMessage(outputList.get(0)));
|
||||
assertEquals("Supplied info message wasn't found in the log",
|
||||
"Simple info message",
|
||||
extractMessage(outputList.get(0)));
|
||||
|
||||
outputList.clear();
|
||||
|
||||
configuredLogger.warn("Simple warn message");
|
||||
configuredLogger.error("Simple error message");
|
||||
assertEquals("The other levels should have been captured", 2, outputList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWarn() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.WARN);
|
||||
|
||||
configuredLogger.trace("Simple trace message");
|
||||
configuredLogger.debug("Simple debug message");
|
||||
configuredLogger.info("Simple info message");
|
||||
assertEquals("Lower levels should have been ignored", 0, outputList.size());
|
||||
|
||||
assertTrue("Warn level should be enabled for this test", configuredLogger.isWarnEnabled());
|
||||
configuredLogger.warn("Simple warn message");
|
||||
|
||||
assertEquals("Warn message should've been captured", 1, outputList.size());
|
||||
assertTrue("Message should be logged in warn level", isWarnMessage(outputList.get(0)));
|
||||
assertEquals("Supplied warn message wasn't found in the log",
|
||||
"Simple warn message",
|
||||
extractMessage(outputList.get(0)));
|
||||
|
||||
outputList.clear();
|
||||
|
||||
configuredLogger.error("Simple error message");
|
||||
assertEquals("The other levels should have been captured", 1, outputList.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testError() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.ERROR);
|
||||
|
||||
configuredLogger.trace("Simple trace message");
|
||||
configuredLogger.debug("Simple debug message");
|
||||
configuredLogger.info("Simple info message");
|
||||
configuredLogger.warn("Simple warn message");
|
||||
assertEquals("Lower levels should have been ignored", 0, outputList.size());
|
||||
|
||||
assertTrue("Error level should be enabled for this test", configuredLogger.isErrorEnabled());
|
||||
configuredLogger.error("Simple error message");
|
||||
|
||||
assertEquals("Error message should've been captured", 1, outputList.size());
|
||||
assertTrue("Message should be logged in error level", isErrorMessage(outputList.get(0)));
|
||||
assertEquals("Supplied error message wasn't found in the log",
|
||||
"Simple error message",
|
||||
extractMessage(outputList.get(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatting() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.INFO);
|
||||
|
||||
configuredLogger.info("Some {} string", "formatted");
|
||||
assertEquals("The formatted message should've been captured", 1, outputList.size());
|
||||
assertEquals("Message should've been formatted", "Some formatted string", extractMessage(outputList.get(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testException() {
|
||||
ArrayList<String> outputList = new ArrayList<>();
|
||||
Logger configuredLogger = createLogger(prepareSink(outputList), Level.INFO);
|
||||
|
||||
Exception exception = new RuntimeException("My error");
|
||||
|
||||
configuredLogger.info("Logging with an exception", exception);
|
||||
assertEquals("The formatted message should've been captured", 1, outputList.size());
|
||||
assertEquals("Message should've been formatted",
|
||||
"My error",
|
||||
extractExceptionMessage(outputList.get(0)));
|
||||
|
||||
assertEquals("Message should've been formatted",
|
||||
"java.lang.RuntimeException",
|
||||
extractExceptionType(outputList.get(0)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allows tests to check whether the log message contains a trace message.
|
||||
* Override if needed.
|
||||
* @param message String containing the full log message
|
||||
* @return whether it is a trace message or not
|
||||
*/
|
||||
protected boolean isTraceMessage(String message) {
|
||||
return message.toLowerCase().contains("trace");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows tests to check whether the log message contains a debug message.
|
||||
* Override if needed.
|
||||
* @param message String containing the full log message
|
||||
* @return whether it is a debug message or not
|
||||
*/
|
||||
protected boolean isDebugMessage(String message) {
|
||||
return message.toLowerCase().contains("debug");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows tests to check whether the log message contains an info message.
|
||||
* Override if needed.
|
||||
* @param message String containing the full log message
|
||||
* @return whether it is an info message or not
|
||||
*/
|
||||
protected boolean isInfoMessage(String message) {
|
||||
return message.toLowerCase().contains("info");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows tests to check whether the log message contains a warn message.
|
||||
* Override if needed.
|
||||
* @param message String containing the full log message
|
||||
* @return whether it is a warn message or not
|
||||
*/
|
||||
protected boolean isWarnMessage(String message) {
|
||||
return message.toLowerCase().contains("warn");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows tests to check whether the log message contains an error message.
|
||||
* Override if needed.
|
||||
* @param message String containing the full log message
|
||||
* @return whether it is an error message or not
|
||||
*/
|
||||
protected boolean isErrorMessage(String message) {
|
||||
return message.toLowerCase().contains("error");
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts only the part of the log string that should represent the `message` string.
|
||||
* @param message the full log message
|
||||
* @return only the supplied message
|
||||
*/
|
||||
public abstract String extractMessage(String message);
|
||||
|
||||
/**
|
||||
* Extracts only the part of the log string that should represent the supplied exception message, if any.
|
||||
* @param message the full log message
|
||||
* @return only the supplied exception message
|
||||
*/
|
||||
public abstract String extractExceptionMessage(String message);
|
||||
|
||||
/**
|
||||
* Extracts only the part of the log string that should represent the supplied exception type.
|
||||
* @param message the full log message
|
||||
* @return only the supplied exception type name
|
||||
*/
|
||||
public abstract String extractExceptionType(String message);
|
||||
|
||||
/**
|
||||
* Configures the logger for running the tests.
|
||||
* @param outputStream The output stream for logs to be written to
|
||||
* @param level The expected level the tests will run for this logger
|
||||
* @return a configured logger able to run the tests
|
||||
*/
|
||||
public abstract Logger createLogger(ListAppendingOutputStream outputStream, Level level);
|
||||
|
||||
}
|
||||
|
|
@ -41,6 +41,8 @@ public class SimpleLoggerMultithreadedInitializationTest extends MultithreadedIn
|
|||
//
|
||||
// final int diff = new Random().nextInt(10000);
|
||||
static int NUM_LINES_IN_SLF4J_REPLAY_WARNING = 3;
|
||||
static int NUM_LINES_IN_SLF4J_CONNECTED_WITH_PROVIDER_INFO = 1;
|
||||
|
||||
private final PrintStream oldErr = System.err;
|
||||
final String loggerName = this.getClass().getName();
|
||||
StringPrintStream sps = new StringPrintStream(oldErr, false);
|
||||
|
|
@ -67,7 +69,7 @@ public class SimpleLoggerMultithreadedInitializationTest extends MultithreadedIn
|
|||
|
||||
@Override
|
||||
protected int extraLogEvents() {
|
||||
return NUM_LINES_IN_SLF4J_REPLAY_WARNING;
|
||||
return NUM_LINES_IN_SLF4J_REPLAY_WARNING + NUM_LINES_IN_SLF4J_CONNECTED_WITH_PROVIDER_INFO;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package org.slf4j.simple;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.helpers.Slf4jEnvUtil;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class Slf4jVersionTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void slf4jVersionTest() {
|
||||
|
||||
String version = Slf4jEnvUtil.slf4jVersion();
|
||||
assertNotNull(version);
|
||||
assertTrue(version.startsWith("2"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue