Skip to content

Commit

Permalink
[24] Upgrade to SLF4J 2.0.6.
Browse files Browse the repository at this point in the history
Signed-off-by: James R. Perkins <[email protected]>
  • Loading branch information
jamezp committed Jan 20, 2023
1 parent fa8292f commit 1c1f21f
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 10 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,33 @@ jobs:
- uses: actions/upload-artifact@v3
if: failure()
with:
name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.wildfly-version }}
name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}
path: '**/surefire-reports/*.txt'
legacy-test:
runs-on: ubuntu-latest
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
java: ['11', '17']

steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'
- name: Legacy Test - Java ${{ matrix.java }}
run: |
mvn clean install -U -B
mvn test -Dlegacy.test
- uses: actions/upload-artifact@v3
if: failure()
with:
name: legacy-surefire-reports-${{ matrix.java }}
path: '**/surefire-reports/*.txt'

format-check:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ https://www.slf4j.org/manual.html#swapping[SLF4J binding] which sends log messag
project is currently used in https://wildfly.org[WildFly] and
https://www.redhat.com/en/technologies/jboss-middleware/application-platform[JBoss EAP].

Currently, this supports both SLF4J 2.x and SLF4J 1.7.x. Support for 1.7.x is deprecated and will be removed in future
releases.

== Usage

To use the project you need both SLF4J and JBoss Log Manager on your class path. Then simply add this library and it should
Expand Down
35 changes: 31 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<properties>
<version.org.jboss.logmanager>2.1.19.Final</version.org.jboss.logmanager>
<version.org.slf4j>1.7.36</version.org.slf4j>
<version.org.slf4j>2.0.6</version.org.slf4j>
<!-- Test dependencies -->
<version.org.junit>5.9.2</version.org.junit>
</properties>
Expand Down Expand Up @@ -103,9 +103,6 @@

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
Expand Down Expand Up @@ -174,5 +171,35 @@
</plugins>
</build>
</profile>
<profile>
<id>slf4j-legacy-test</id>
<activation>
<property>
<name>legacy.test</name>
</property>
</activation>
<properties>
<version.org.slf4j>1.7.36</version.org.slf4j>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<skip>true</skip>
<skipMain>true</skipMain>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<failIfNoTests>true</failIfNoTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
67 changes: 67 additions & 0 deletions src/main/java/org/slf4j/impl/JBossSlf4jServiceProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.slf4j.impl;

import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
import org.slf4j.helpers.BasicMarkerFactory;
import org.slf4j.spi.MDCAdapter;
import org.slf4j.spi.SLF4JServiceProvider;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class JBossSlf4jServiceProvider implements SLF4JServiceProvider {

private final ILoggerFactory loggerFactory;
private final IMarkerFactory markerFactory;
private final MDCAdapter mdcAdapter;

public JBossSlf4jServiceProvider() {
this.loggerFactory = new Slf4jLoggerFactory();
this.markerFactory = new BasicMarkerFactory();
this.mdcAdapter = new Slf4jMDCAdapter();
}

@Override
public ILoggerFactory getLoggerFactory() {
return loggerFactory;
}

@Override
public IMarkerFactory getMarkerFactory() {
return markerFactory;
}

@Override
public MDCAdapter getMDCAdapter() {
return mdcAdapter;
}

@Override
public String getRequestedApiVersion() {
return "2.0.6";
}

@Override
public void initialize() {
// do nothing
}
}
9 changes: 8 additions & 1 deletion src/main/java/org/slf4j/impl/Slf4jMDCAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,37 @@
import java.util.Map;

import org.jboss.logmanager.MDC;
import org.slf4j.helpers.BasicMDCAdapter;
import org.slf4j.spi.MDCAdapter;

public final class Slf4jMDCAdapter implements MDCAdapter {
public final class Slf4jMDCAdapter extends BasicMDCAdapter implements MDCAdapter {

@Override
public void put(final String key, final String val) {
MDC.put(key, val);
}

@Override
public String get(final String key) {
return MDC.get(key);
}

@Override
public void remove(final String key) {
MDC.remove(key);
}

@Override
public void clear() {
MDC.clear();
}

@Override
public Map<String, String> getCopyOfContextMap() {
return MDC.copy();
}

@Override
public void setContextMap(final Map contextMap) {
MDC.clear();
for (Map.Entry<?, ?> entry : ((Map<?, ?>) contextMap).entrySet()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/slf4j/impl/StaticLoggerBinder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2014 Red Hat, Inc., and individual contributors
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,6 +22,7 @@
import org.slf4j.ILoggerFactory;
import org.slf4j.spi.LoggerFactoryBinder;

@Deprecated(forRemoval = true)
public final class StaticLoggerBinder implements LoggerFactoryBinder {

public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
Expand All @@ -31,7 +32,7 @@ public final class StaticLoggerBinder implements LoggerFactoryBinder {
* The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.7.2";
public static String REQUESTED_API_VERSION = "2.0.6";

public ILoggerFactory getLoggerFactory() {
return new Slf4jLoggerFactory();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/slf4j/impl/StaticMDCBinder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2014 Red Hat, Inc., and individual contributors
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,6 +21,7 @@

import org.slf4j.spi.MDCAdapter;

@Deprecated(forRemoval = true)
public final class StaticMDCBinder {

public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/slf4j/impl/StaticMarkerBinder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2014 Red Hat, Inc., and individual contributors
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -23,6 +23,7 @@
import org.slf4j.helpers.BasicMarkerFactory;
import org.slf4j.spi.MarkerFactoryBinder;

@Deprecated(forRemoval = true)
public final class StaticMarkerBinder implements MarkerFactoryBinder {

public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# JBoss, Home of Professional Open Source.
#
# Copyright 2023 Red Hat, Inc., and individual contributors
# as indicated by the @author tags.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.slf4j.impl.JBossSlf4jServiceProvider

0 comments on commit 1c1f21f

Please sign in to comment.