[Git][java-team/jboss-logging][upstream] New upstream version 3.5.0
Markus Koschany (@apo)
gitlab at salsa.debian.org
Wed May 4 12:02:25 BST 2022
Markus Koschany pushed to branch upstream at Debian Java Maintainers / jboss-logging
Commits:
21561aa7 by Markus Koschany at 2022-05-04T12:37:34+02:00
New upstream version 3.5.0
- - - - -
10 changed files:
- .github/workflows/ci.yml
- + README.adoc
- pom.xml
- + src/main/java/module-info.yml
- src/main/java/org/jboss/logging/JBossLogManagerProvider.java
- src/main/java/org/jboss/logging/JDKLoggerProvider.java
- src/main/java/org/jboss/logging/Log4j2LoggerProvider.java
- src/main/java/org/jboss/logging/Log4jLoggerProvider.java
- src/main/java/org/jboss/logging/LoggerProviders.java
- src/main/java/org/jboss/logging/Slf4jLoggerProvider.java
Changes:
=====================================
.github/workflows/ci.yml
=====================================
@@ -19,12 +19,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest ]
- java: ['8', '11', '17']
+ java: ['11', '17']
steps:
- uses: actions/checkout at v2
- name: Set up JDK ${{ matrix.java }}
- uses: actions/setup-java at v2
+ uses: actions/setup-java at v3
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
=====================================
README.adoc
=====================================
@@ -0,0 +1,77 @@
+= JBoss Logging
+
+JBoss Logging is a logging facade which can bind to different log managers allowing your applications to be log manager
+agnostic.
+
+== Usage
+
+JBoss Logging is similar to other logging facades in the way you get a logger and log messages. One thing to note is
+the format style log methods will only format the message if the log level is enabled. This helps with performance of
+objects which may have complex `toString()` methods.
+
+[source,java]
+----
+private static final Logger LOGGER = Logger.getLogger(Customer.class);
+
+public Customer getCustomer(final int id) {
+ LOGGER.debugf("Looking up customer %d", id);
+ try {
+ final Customer customer = findCustomer(id);
+ LOGGER.tracef("Found customer: %s", customer);
+ return customer;
+ } catch (Exception e) {
+ LOGGER.errorf(e, "Error looking up customer %d", id);
+ }
+ return null;
+}
+----
+
+=== Supported Log Managers
+
+The following are the supported log managers and listed in the order the attempt to discover the provider is done.
+
+1. JBoss Log Manager
+2. https://logging.apache.org/log4j/2.x/[Log4j 2]
+3. https://logback.qos.ch/[SLF4J and Logback]
+4. https://logging.apache.org/log4j/1.2/[log4j] (note this log manager is EOL'd)
+5. Java Util Logging
+
+You can define the specific log manager you want to use by specifying the `org.jboss.logging.provider` system property.
+The following is the mapping of the property value to the log manager.
+
+|===
+|Property Value |Log Manager
+
+|jboss
+|JBoss Log Manager
+
+|jdk
+|Java Util Logging
+
+|log4j2
+|Log4j 2
+
+|log4j
+|log4j
+
+|slf4j
+|SLF4J and Logback
+|===
+
+=== Custom Provider
+
+You can also implement your own `org.jboss.logging.LoggerProvider` which would be loaded from a `ServiceLoader`. Simply
+implement the API and add a `META-INF/services/org.jboss.logging.LoggerProvider` file with the fully qualified class
+name of your implementation to your library. If the system property is not defined, your implementation should be
+discovered.
+
+=== Maven Dependency
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>${version.org.jboss.logging}</version>
+</dependency>
+----
\ No newline at end of file
=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
- <version>3.4.3.Final</version>
+ <version>3.5.0.Final</version>
<packaging>jar</packaging>
<name>JBoss Logging 3</name>
<url>http://www.jboss.org</url>
@@ -24,7 +24,7 @@
<licenses>
<license>
<name>Apache License, version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
@@ -32,15 +32,22 @@
<properties>
<!-- Dependency versions -->
<version.ch.qos.logback>1.2.8</version.ch.qos.logback>
+ <version.module-info>1.2</version.module-info>
<version.org.apache.log4j>1.2.17</version.org.apache.log4j>
<version.org.apache.logging.log4j>2.17.1</version.org.apache.logging.log4j>
<version.org.jboss.logmanager>2.1.18.Final</version.org.jboss.logmanager>
<version.org.junit>5.8.2</version.org.junit>
<version.org.sfl4j>1.7.32</version.org.sfl4j>
+ <version.surefire.plugin>3.0.0-M5</version.surefire.plugin>
<!-- Override the parent version to compile with Java 17 -->
<version.bundle.plugin>5.1.3</version.bundle.plugin>
+ <!-- Require at least Java 11 to compile -->
+ <jdk.min.version>11</jdk.min.version>
+ <maven.compiler.target>11</maven.compiler.target>
+ <maven.compiler.source>11</maven.compiler.source>
+
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
<cp.test.classes.dir>${project.build.directory}${file.separator}cp-test-classes</cp.test.classes.dir>
</properties>
@@ -117,14 +124,22 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <release>11</release>
+ <testRelease>11</testRelease>
+ </configuration>
<executions>
<execution>
- <id>default-test-compile</id>
+ <id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
<configuration>
+ <!-- This is a hack which allows the test-compile to succeed with missing optional modules.
+ See https://issues.apache.org/jira/browse/MCOMPILER-494 for details.
+ -->
+ <release>8</release>
<testExcludes>
<testExclude>**/*ClassPathTestCase.java</testExclude>
</testExcludes>
@@ -137,6 +152,10 @@
</goals>
<phase>test-compile</phase>
<configuration>
+ <!-- This is a hack which allows the test-compile to succeed with missing optional modules.
+ See https://issues.apache.org/jira/browse/MCOMPILER-494 for details.
+ -->
+ <release>8</release>
<outputDirectory>${cp.test.classes.dir}</outputDirectory>
<skip>${skip.cp.tests}</skip>
<testIncludes>
@@ -156,6 +175,7 @@
<!-- Required so we can test the various providers -->
<reuseForks>false</reuseForks>
<skip>true</skip>
+ <useModulePath>false</useModulePath>
</configuration>
<executions>
<execution>
@@ -287,6 +307,17 @@
</archive>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <additionalJOption>--no-module-directories</additionalJOption>
+ <doclint>none</doclint>
+ <!-- Get around issues with module errors when producing JavaDocs for releases. The generated JavaDoc
+ is still generated with the Java 9+ style.
+ -->
+ <release>8</release>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
@@ -320,6 +351,20 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>io.github.dmlloyd.module-info</groupId>
+ <artifactId>module-info</artifactId>
+ <version>${version.module-info}</version>
+ <executions>
+ <execution>
+ <id>module-info</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
=====================================
src/main/java/module-info.yml
=====================================
@@ -0,0 +1,14 @@
+name: org.jboss.logging
+
+requires:
+ - module: org.jboss.logmanager
+ static: true
+ - module: org.slf4j
+ static: true
+ - module: log4j.api # log4j 1, theoretically
+ static: true
+ - module: org.apache.logging.log4j
+ static: true
+
+uses:
+ - org.jboss.logging.LoggerProvider
=====================================
src/main/java/org/jboss/logging/JBossLogManagerProvider.java
=====================================
@@ -30,23 +30,25 @@ import org.jboss.logmanager.NDC;
import static org.jboss.logmanager.Logger.AttachmentKey;
-final class JBossLogManagerProvider implements LoggerProvider {
+/**
+ * An implementation of the {@linkplain LoggerProvider log provider} for the JBoss Log Manager.
+ */
+public final class JBossLogManagerProvider implements LoggerProvider {
- private static final AttachmentKey<Logger> KEY = new AttachmentKey<Logger>();
- private static final AttachmentKey<ConcurrentMap<String, Logger>> LEGACY_KEY = new AttachmentKey<ConcurrentMap<String, Logger>>();
+ private static final AttachmentKey<Logger> KEY = new AttachmentKey<>();
+ private static final AttachmentKey<ConcurrentMap<String, Logger>> LEGACY_KEY = new AttachmentKey<>();
+ @Override
public Logger getLogger(final String name) {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- return AccessController.doPrivileged(new PrivilegedAction<Logger>() {
- public Logger run() {
- try {
- return doGetLogger(name) ;
- } catch (NoSuchMethodError ignore) {
- }
- // fallback
- return doLegacyGetLogger(name);
+ return AccessController.doPrivileged((PrivilegedAction<Logger>) () -> {
+ try {
+ return doGetLogger(name) ;
+ } catch (NoSuchMethodError ignore) {
}
+ // fallback
+ return doLegacyGetLogger(name);
});
} else {
try {
@@ -62,7 +64,7 @@ final class JBossLogManagerProvider implements LoggerProvider {
final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger("");
ConcurrentMap<String, Logger> loggers = lmLogger.getAttachment(LEGACY_KEY);
if (loggers == null) {
- loggers = new ConcurrentHashMap<String, Logger>();
+ loggers = new ConcurrentHashMap<>();
final ConcurrentMap<String, Logger> appearing = lmLogger.attachIfAbsent(LEGACY_KEY, loggers);
if (appearing != null) {
loggers = appearing;
@@ -98,52 +100,63 @@ final class JBossLogManagerProvider implements LoggerProvider {
}
}
+ @Override
public void clearMdc() {
MDC.clear();
}
+ @Override
public Object putMdc(final String key, final Object value) {
- return MDC.put(key, String.valueOf(value));
+ return MDC.putObject(key, value);
}
+ @Override
public Object getMdc(final String key) {
- return MDC.get(key);
+ return MDC.getObject(key);
}
+ @Override
public void removeMdc(final String key) {
- MDC.remove(key);
+ MDC.removeObject(key);
}
- @SuppressWarnings({ "unchecked" })
+ @Override
public Map<String, Object> getMdcMap() {
// we can re-define the erasure of this map because MDC does not make further use of the copy
- return (Map)MDC.copy();
+ return MDC.copyObject();
}
+ @Override
public void clearNdc() {
NDC.clear();
}
+ @Override
public String getNdc() {
return NDC.get();
}
+ @Override
public int getNdcDepth() {
return NDC.getDepth();
}
+ @Override
public String popNdc() {
return NDC.pop();
}
+ @Override
public String peekNdc() {
return NDC.get();
}
+ @Override
public void pushNdc(final String message) {
NDC.push(message);
}
+ @Override
public void setNdcMaxDepth(final int maxDepth) {
NDC.trimTo(maxDepth);
}
=====================================
src/main/java/org/jboss/logging/JDKLoggerProvider.java
=====================================
@@ -18,8 +18,13 @@
package org.jboss.logging;
-final class JDKLoggerProvider extends AbstractMdcLoggerProvider implements LoggerProvider {
+/**
+ * An implementation of the {@linkplain LoggerProvider log provider} for the
+ * {@linkplain java.util.logging.LogManager JDK Log Manager}.
+ */
+public final class JDKLoggerProvider extends AbstractMdcLoggerProvider implements LoggerProvider {
+ @Override
public Logger getLogger(final String name) {
return new JDKLogger(name);
}
=====================================
src/main/java/org/jboss/logging/Log4j2LoggerProvider.java
=====================================
@@ -23,7 +23,13 @@ import java.util.Map;
import org.apache.logging.log4j.ThreadContext;
-final class Log4j2LoggerProvider implements LoggerProvider {
+/**
+ * An implementation of the {@linkplain LoggerProvider log provider} for Log4j 2.
+ * <p>
+ * This binds to the Log4j 2 API and does not require a specific implementation of the Log4j 2 API.
+ * </p>
+ */
+public final class Log4j2LoggerProvider implements LoggerProvider {
@Override
public Log4j2Logger getLogger(String name) {
@@ -56,7 +62,7 @@ final class Log4j2LoggerProvider implements LoggerProvider {
@Override
public Map<String, Object> getMdcMap() {
- return new HashMap<String, Object>(ThreadContext.getImmutableContext());
+ return new HashMap<>(ThreadContext.getImmutableContext());
}
@Override
=====================================
src/main/java/org/jboss/logging/Log4jLoggerProvider.java
=====================================
@@ -24,26 +24,37 @@ import java.util.Map;
import org.apache.log4j.MDC;
import org.apache.log4j.NDC;
-final class Log4jLoggerProvider implements LoggerProvider {
+/**
+ * An implementation of the {@linkplain LoggerProvider log provider} for log4j.
+ * <p>
+ * Please note that log4j reached end of life on August 5, 2015. Prefer using a log manager and provider.
+ * </p>
+ */
+public final class Log4jLoggerProvider implements LoggerProvider {
+ @Override
public Logger getLogger(final String name) {
return new Log4jLogger("".equals(name) ? "ROOT" : name);
}
+ @Override
public void clearMdc() {
MDC.clear();
}
+ @Override
public Object getMdc(String key) {
return MDC.get(key);
}
+ @Override
public Map<String, Object> getMdcMap() {
@SuppressWarnings("unchecked")
final Map<String, Object> map = MDC.getContext();
- return map == null ? Collections.<String, Object>emptyMap() : map;
+ return map == null ? Collections.emptyMap() : map;
}
+ @Override
public Object putMdc(String key, Object val) {
try {
return MDC.get(key);
@@ -52,34 +63,42 @@ final class Log4jLoggerProvider implements LoggerProvider {
}
}
+ @Override
public void removeMdc(String key) {
MDC.remove(key);
}
+ @Override
public void clearNdc() {
NDC.remove();
}
+ @Override
public String getNdc() {
return NDC.get();
}
+ @Override
public int getNdcDepth() {
return NDC.getDepth();
}
+ @Override
public String peekNdc() {
return NDC.peek();
}
+ @Override
public String popNdc() {
return NDC.pop();
}
+ @Override
public void pushNdc(String message) {
NDC.push(message);
}
+ @Override
public void setNdcMaxDepth(int maxDepth) {
NDC.setMaxDepth(maxDepth);
}
=====================================
src/main/java/org/jboss/logging/LoggerProviders.java
=====================================
@@ -81,20 +81,20 @@ final class LoggerProviders {
// nope...
}
try {
- // MUST try Log4j 2.x BEFORE Log4j 1.x because Log4j 2.x also passes Log4j 1.x test in some circumstances
return tryLog4j2(cl, null);
} catch (Throwable t) {
// nope...
}
try {
- return tryLog4j(cl, null);
+ // only use slf4j if Logback is in use
+ Class.forName("ch.qos.logback.classic.Logger", false, cl);
+ return trySlf4j(null);
} catch (Throwable t) {
// nope...
}
try {
- // only use slf4j if Logback is in use
- Class.forName("ch.qos.logback.classic.Logger", false, cl);
- return trySlf4j(null);
+ // log4j has been EOL'd since 2015. It should be checked last.
+ return tryLog4j(cl, null);
} catch (Throwable t) {
// nope...
}
=====================================
src/main/java/org/jboss/logging/Slf4jLoggerProvider.java
=====================================
@@ -26,8 +26,12 @@ import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.slf4j.spi.LocationAwareLogger;
-final class Slf4jLoggerProvider extends AbstractLoggerProvider implements LoggerProvider {
+/**
+ * An implementation of the {@linkplain LoggerProvider log provider} for slf4j with Logback as the log manager.
+ */
+public final class Slf4jLoggerProvider extends AbstractLoggerProvider implements LoggerProvider {
+ @Override
public Logger getLogger(final String name) {
org.slf4j.Logger l = LoggerFactory.getLogger(name);
if (l instanceof LocationAwareLogger) {
@@ -36,10 +40,12 @@ final class Slf4jLoggerProvider extends AbstractLoggerProvider implements Logger
return new Slf4jLogger(name, l);
}
+ @Override
public void clearMdc() {
MDC.clear();
}
+ @Override
public Object putMdc(final String key, final Object value) {
try {
return MDC.get(key);
@@ -52,17 +58,19 @@ final class Slf4jLoggerProvider extends AbstractLoggerProvider implements Logger
}
}
+ @Override
public Object getMdc(final String key) {
return MDC.get(key);
}
+ @Override
public void removeMdc(final String key) {
MDC.remove(key);
}
- @SuppressWarnings("unchecked")
+ @Override
public Map<String, Object> getMdcMap() {
- final Map copy = MDC.getCopyOfContextMap();
+ final Map<String, String> copy = MDC.getCopyOfContextMap();
return copy == null ? Collections.emptyMap() : new LinkedHashMap<>(copy);
}
}
View it on GitLab: https://salsa.debian.org/java-team/jboss-logging/-/commit/21561aa726474b9ef49bb25fc7d3d06584978a88
--
View it on GitLab: https://salsa.debian.org/java-team/jboss-logging/-/commit/21561aa726474b9ef49bb25fc7d3d06584978a88
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220504/3aefa35f/attachment.htm>
More information about the pkg-java-commits
mailing list