[Git][java-team/jboss-logging][master] 9 commits: Switch to debhelper-compat = 13.
Markus Koschany (@apo)
gitlab at salsa.debian.org
Sat Sep 25 22:43:55 BST 2021
Markus Koschany pushed to branch master at Debian Java Maintainers / jboss-logging
Commits:
7e0433d9 by Markus Koschany at 2021-09-25T22:53:21+02:00
Switch to debhelper-compat = 13.
- - - - -
547a3a93 by Markus Koschany at 2021-09-25T22:53:36+02:00
Declare compliance with Debian Policy 4.6.0.
- - - - -
1d23c973 by Markus Koschany at 2021-09-25T22:54:06+02:00
Update copyright years
- - - - -
9e13ffb6 by Markus Koschany at 2021-09-25T22:58:31+02:00
Update debian watch
- - - - -
b69e25f4 by Markus Koschany at 2021-09-25T22:59:04+02:00
New upstream version 3.4.2
- - - - -
37ef9195 by Markus Koschany at 2021-09-25T22:59:05+02:00
Update upstream source from tag 'upstream/3.4.2'
Update to upstream version '3.4.2'
with Debian dir f4104dd34b1ab9a25a7b3230e72fa1394c952618
- - - - -
8213184c by Markus Koschany at 2021-09-25T23:01:32+02:00
Start new changelog entry
- - - - -
e40e6a90 by Markus Koschany at 2021-09-25T23:12:46+02:00
B-D on liblogback-java
- - - - -
3c72bbae by Markus Koschany at 2021-09-25T23:21:44+02:00
Update changelog
- - - - -
23 changed files:
- + .github/workflows/ci.yml
- debian/changelog
- debian/control
- debian/copyright
- debian/watch
- pom.xml
- src/main/java/org/jboss/logging/Log4j2Logger.java
- src/main/java/org/jboss/logging/LoggerProviders.java
- + src/test/java/org/jboss/logging/AbstractClassPathTestCase.java
- + src/test/java/org/jboss/logging/AbstractLoggerTestCase.java
- + src/test/java/org/jboss/logging/CustomProviderTestCase.java
- + src/test/java/org/jboss/logging/JBossLogManagerClassPathTestCase.java
- + src/test/java/org/jboss/logging/JBossLogManagerProviderTestCase.java
- + src/test/java/org/jboss/logging/JulClassPathTestCase.java
- + src/test/java/org/jboss/logging/JulProviderTestCase.java
- + src/test/java/org/jboss/logging/Log4j2ClassPathTestCase.java
- + src/test/java/org/jboss/logging/Log4j2ProviderTestCase.java
- + src/test/java/org/jboss/logging/Log4jClassPathTestCase.java
- + src/test/java/org/jboss/logging/Log4jProviderTestCase.java
- + src/test/java/org/jboss/logging/Slf4jClassPathTestCase.java
- + src/test/java/org/jboss/logging/Slf4jProviderTestCase.java
- + src/test/resources/META-INF/services/org.jboss.logging.LoggerProvider
- + src/test/resources/log4j2-test.xml
Changes:
=====================================
.github/workflows/ci.yml
=====================================
@@ -0,0 +1,42 @@
+# This workflow will build a Java project with Maven
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: JBoss Logging - CI
+
+on:
+ push:
+ branches:
+ - '**'
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review]
+
+
+jobs:
+ build:
+ name: ${{ matrix.os }}-jdk${{ matrix.java }}
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [ubuntu-latest, windows-latest ]
+ java: ['1.8', '11']
+
+ steps:
+ - uses: actions/checkout at v2
+ - uses: actions/cache at v1
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Set up JDK ${{ matrix.java }}
+ uses: actions/setup-java at v1
+ with:
+ java-version: ${{ matrix.java }}
+ - name: Build and Test on ${{ matrix.java }}
+ run: mvn clean install
+ - uses: actions/upload-artifact at v2
+ if: failure()
+ with:
+ name: surefire-reports-${{ matrix.os }}-${{ matrix.java }}
+ path: '**/surefire-reports/*.txt'
\ No newline at end of file
=====================================
debian/changelog
=====================================
@@ -1,3 +1,12 @@
+jboss-logging (3.4.2-1) unstable; urgency=medium
+
+ * New upstream version 3.4.2.
+ * Switch to debhelper-compat = 13.
+ * Declare compliance with Debian Policy 4.6.0.
+ * Build-depend on liblogback-java.
+
+ -- Markus Koschany <apo at debian.org> Sat, 25 Sep 2021 23:01:27 +0200
+
jboss-logging (3.4.1-1) unstable; urgency=medium
* New upstream version 3.4.1.
=====================================
debian/control
=====================================
@@ -5,16 +5,17 @@ Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.or
Uploaders:
Markus Koschany <apo at debian.org>
Build-Depends:
- debhelper-compat (= 12),
+ debhelper-compat (= 13),
default-jdk,
default-jdk-doc,
libjboss-logmanager-java,
liblog4j1.2-java,
liblog4j2-java (>= 2.0),
+ liblogback-java,
libmaven-bundle-plugin-java,
libmaven-javadoc-plugin-java,
maven-debian-helper (>= 1.5)
-Standards-Version: 4.4.0
+Standards-Version: 4.6.0
Vcs-Git: https://salsa.debian.org/java-team/jboss-logging.git
Vcs-Browser: https://salsa.debian.org/java-team/jboss-logging
Homepage: http://www.jboss.org
=====================================
debian/copyright
=====================================
@@ -3,11 +3,11 @@ Upstream-Name: JBoss Logging 3
Source: https://github.com/jboss-logging/jboss-logging
Files: *
-Copyright: 2010-2019, Redhat, Inc.
+Copyright: 2010-2021, Redhat, Inc.
License: Apache-2.0
Files: debian/*
-Copyright: 2015-2019, Markus Koschany <apo at debian.org>
+Copyright: 2015-2021, Markus Koschany <apo at debian.org>
License: Apache-2.0
License: Apache-2.0
=====================================
debian/watch
=====================================
@@ -1,4 +1,4 @@
-version=3
-opts=dversionmangle=s/(\da?)[\+\.\-~](?:dfsg|debian|ds|repack|repacked)\.?\d*$/$1/,uversionmangle=s/\.CR/~rc/g;s/\.Beta/~beta/;s/\.GA//;s/\.Final// \
-https://github.com/jboss-logging/jboss-logging/tags \
-.*/archive/(?:upstream/)?(?:v||version-|release-|X|R|r)(\d\S*)\.tar\.gz
+version=4
+opts=dversionmangle=s/(\da?)[\+\.\-~](?:dfsg|debian|ds|repack|repacked)\.?\d*$/$1/,uversionmangle=s/\.CR/~rc/g;s/\.Beta/~beta/;s/\.GA//;s/\.Final//;s/.+\/v?(\d\S+)\.tar\.gz/jboss-logging-$1\.tar\.gz/ \
+https://github.com/jboss-logging/jboss-logging/tags .*/v?(\d\S+)\.tar\.gz
+
=====================================
pom.xml
=====================================
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
- <version>3.4.1.Final</version>
+ <version>3.4.2.Final</version>
<packaging>jar</packaging>
<name>JBoss Logging 3</name>
<url>http://www.jboss.org</url>
@@ -18,7 +18,7 @@
<parent>
<groupId>org.jboss</groupId>
<artifactId>jboss-parent</artifactId>
- <version>34</version>
+ <version>37</version>
</parent>
<licenses>
@@ -31,12 +31,29 @@
<properties>
<!-- Dependency versions -->
+ <version.ch.qos.logback>1.2.3</version.ch.qos.logback>
<version.org.apache.log4j>1.2.16</version.org.apache.log4j>
<version.org.apache.logging.log4j>2.11.2</version.org.apache.logging.log4j>
<version.org.jboss.logmanager>2.1.9.Final</version.org.jboss.logmanager>
+ <version.org.junit>5.7.0</version.org.junit>
<version.org.sfl4j>1.7.25</version.org.sfl4j>
+
+ <maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
+ <cp.test.classes.dir>${project.build.directory}${file.separator}cp-test-classes</cp.test.classes.dir>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>${version.org.junit}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>org.jboss.logmanager</groupId>
@@ -72,16 +89,192 @@
<version>${version.org.sfl4j}</version>
<scope>provided</scope>
</dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>${version.ch.qos.logback}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>${version.org.apache.logging.log4j}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-test-compile</id>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ <phase>test-compile</phase>
+ <configuration>
+ <testExcludes>
+ <testExclude>**/*ClassPathTestCase.java</testExclude>
+ </testExcludes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>cp-test-compile</id>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ <phase>test-compile</phase>
+ <configuration>
+ <outputDirectory>${cp.test.classes.dir}</outputDirectory>
+ <skip>${skip.cp.tests}</skip>
+ <testIncludes>
+ <testInclude>**/*ClassPathTestCase.java</testInclude>
+ </testIncludes>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <redirectTestOutputToFile>${maven.test.redirectTestOutputToFile}</redirectTestOutputToFile>
+ <!-- Required so we can test the various providers -->
+ <reuseForks>false</reuseForks>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <excludes>
+ <exclude>**/*ClassPathTestCase.java</exclude>
+ </excludes>
+ <systemPropertyVariables>
+ <!-- This is required as JUnit 5 initializes a logger too early for it to be set
+ in the JBossLogManagerTestCase. -->
+ <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ <execution>
+ <id>jboss-logmanager-cp-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <testClassesDirectory>${cp.test.classes.dir}</testClassesDirectory>
+ <includes>
+ <include>**/JBossLogManagerClassPathTestCase.java</include>
+ </includes>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.apache.logging.log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.slf4j</classpathDependencyExclude>
+ <classpathDependencyExclude>ch.qos.logback</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ <systemPropertyVariables>
+ <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ <execution>
+ <id>log4j2-cp-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ <configuration>
+ <skip>false</skip>
+ <testClassesDirectory>${cp.test.classes.dir}</testClassesDirectory>
+ <includes>
+ <include>**/Log4j2ClassPathTestCase.java</include>
+ </includes>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.jboss.logmanager</classpathDependencyExclude>
+ <classpathDependencyExclude>log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.slf4j</classpathDependencyExclude>
+ <classpathDependencyExclude>ch.qos.logback</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>log4j-cp-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ <configuration>
+ <skip>false</skip>
+ <testClassesDirectory>${cp.test.classes.dir}</testClassesDirectory>
+ <includes>
+ <include>**/Log4jClassPathTestCase.java</include>
+ </includes>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.apache.logging.log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.jboss.logmanager</classpathDependencyExclude>
+ <classpathDependencyExclude>org.slf4j</classpathDependencyExclude>
+ <classpathDependencyExclude>ch.qos.logback</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>slf4j-cp-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <phase>test</phase>
+ <configuration>
+ <skip>false</skip>
+ <testClassesDirectory>${cp.test.classes.dir}</testClassesDirectory>
+ <includes>
+ <include>**/Slf4jClassPathTestCase.java</include>
+ </includes>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.apache.logging.log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.jboss.logmanager</classpathDependencyExclude>
+ <classpathDependencyExclude>log4j</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>jul-cp-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <testClassesDirectory>${cp.test.classes.dir}</testClassesDirectory>
+ <includes>
+ <include>**/JulClassPathTestCase.java</include>
+ </includes>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.apache.logging.log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.jboss.logmanager</classpathDependencyExclude>
+ <classpathDependencyExclude>log4j</classpathDependencyExclude>
+ <classpathDependencyExclude>org.slf4j</classpathDependencyExclude>
+ <classpathDependencyExclude>ch.qos.logback</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<!-- Adding OSGI metadata to the JAR without changing the packaging type. -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
=====================================
src/main/java/org/jboss/logging/Log4j2Logger.java
=====================================
@@ -52,7 +52,7 @@ final class Log4j2Logger extends Logger {
if (this.logger.isEnabled(translatedLevel)) {
try {
this.logger.logMessage(loggerClassName, translatedLevel, null,
- (parameters == null || parameters.length == 0) ? this.messageFactory.newMessage(message) : this.messageFactory.newMessage(String.valueOf(message), parameters),
+ (parameters == null || parameters.length == 0) ? this.messageFactory.newMessage(String.valueOf(message)) : this.messageFactory.newMessage(String.valueOf(message), parameters),
thrown);
} catch (Throwable ignored) { }
}
=====================================
src/main/java/org/jboss/logging/LoggerProviders.java
=====================================
@@ -147,7 +147,7 @@ final class LoggerProviders {
private static void logProvider(final LoggerProvider provider, final String via) {
// Log a debug message indicating which logger we are using
- final Logger logger = provider.getLogger(LoggerProviders.class.getPackage().getName());
+ final Logger logger = provider.getLogger("org.jboss.logging");
if (via == null) {
logger.debugf("Logging Provider: %s", provider.getClass().getName());
} else {
=====================================
src/test/java/org/jboss/logging/AbstractClassPathTestCase.java
=====================================
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+abstract class AbstractClassPathTestCase {
+
+ @Test
+ public void testLogger() {
+ final Logger logger = Logger.getLogger(getClass());
+ Assertions.assertEquals(getLoggerClass(), logger.getClass());
+ }
+
+ abstract Class<? extends Logger> getLoggerClass();
+}
=====================================
src/test/java/org/jboss/logging/AbstractLoggerTestCase.java
=====================================
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+abstract class AbstractLoggerTestCase {
+
+ @AfterAll
+ public static void clearProviderProperty() {
+ System.clearProperty("org.jboss.logging.provider");
+ }
+
+ @AfterEach
+ public void clearDiagnostics() {
+ MDC.clear();
+ NDC.clear();
+ }
+
+ @Test
+ public void testLogger() {
+ Assertions.assertEquals(getLoggerClass(), getLogger().getClass());
+ }
+
+ @Test
+ public void testLog() {
+ for (Logger.Level level : Logger.Level.values()) {
+ testLog(level);
+ }
+ }
+
+ @Test
+ public void testTrace() {
+ getLogger().trace("Test log level TRACE");
+ testLog("Test log level TRACE", Logger.Level.TRACE);
+ }
+
+ @Test
+ public void testDebug() {
+ getLogger().debug("Test log level DEBUG");
+ testLog("Test log level DEBUG", Logger.Level.DEBUG);
+ }
+
+ @Test
+ public void testInfo() {
+ getLogger().info("Test log level INFO");
+ testLog("Test log level INFO", Logger.Level.INFO);
+ }
+
+ @Test
+ public void testWarn() {
+ getLogger().warn("Test log level WARN");
+ testLog("Test log level WARN", Logger.Level.WARN);
+ }
+
+ @Test
+ public void testError() {
+ getLogger().error("Test log level ERROR");
+ testLog("Test log level ERROR", Logger.Level.ERROR);
+ }
+
+ @Test
+ public void testFatal() {
+ getLogger().fatal("Test log level FATAL");
+ testLog("Test log level FATAL", Logger.Level.FATAL);
+ }
+
+ abstract void testLog(Logger.Level level);
+
+ abstract void testLog(String msg, Logger.Level level);
+
+ abstract Logger getLogger();
+
+ abstract Class<? extends Logger> getLoggerClass();
+}
=====================================
src/test/java/org/jboss/logging/CustomProviderTestCase.java
=====================================
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class CustomProviderTestCase {
+
+ @Test
+ public void testLogger() {
+ final Logger logger = Logger.getLogger(CustomProviderTestCase.class);
+ Assertions.assertEquals(TestLogger.class, logger.getClass());
+ }
+
+ public static class TestProvider extends AbstractMdcLoggerProvider implements LoggerProvider {
+
+ @Override
+ public Logger getLogger(final String name) {
+ return new TestLogger(name);
+ }
+ }
+
+ static class TestLogger extends Logger {
+
+ /**
+ * Construct a new instance.
+ *
+ * @param name the logger category name
+ */
+ protected TestLogger(final String name) {
+ super(name);
+ }
+
+ @Override
+ protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {
+
+ }
+
+ @Override
+ protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) {
+
+ }
+
+ @Override
+ public boolean isEnabled(final Level level) {
+ return true;
+ }
+ }
+}
=====================================
src/test/java/org/jboss/logging/JBossLogManagerClassPathTestCase.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class JBossLogManagerClassPathTestCase extends AbstractClassPathTestCase {
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return JBossLogManagerLogger.class;
+ }
+}
=====================================
src/test/java/org/jboss/logging/JBossLogManagerProviderTestCase.java
=====================================
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.jboss.logmanager.LogContext;
+import org.jboss.logmanager.LogContextSelector;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class JBossLogManagerProviderTestCase extends AbstractLoggerTestCase {
+ private static final LogContextSelector DEFAULT_SELECTOR = LogContext.getLogContextSelector();
+ private static final AtomicBoolean SET_LOG_MANAGER = new AtomicBoolean(true);
+
+ private LogContext logContext;
+ private TestHandler handler;
+ private Logger logger;
+
+ @BeforeAll
+ public static void setup() {
+ SET_LOG_MANAGER.set(System.getProperty("java.util.logging.manager") == null);
+ if (SET_LOG_MANAGER.get()) {
+ System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
+ }
+ System.setProperty("org.jboss.logging.provider", "jboss");
+ }
+
+ @AfterAll
+ public static void tearDown() {
+ if (SET_LOG_MANAGER.get()) {
+ System.clearProperty("java.util.logging.manager");
+ }
+ }
+
+ @BeforeEach
+ public void setupLogContext() {
+ logContext = LogContext.create();
+ LogContext.setLogContextSelector(() -> logContext);
+ logger = Logger.getLogger(getClass());
+ handler = createHandler(logContext, logger.getName());
+ }
+
+ @AfterEach
+ public void closeLogContext() throws Exception {
+ logContext.close();
+ LogContext.setLogContextSelector(DEFAULT_SELECTOR);
+ }
+
+ @Test
+ public void testMdc() {
+ MDC.put("test.key", "value");
+ Assertions.assertEquals("value", MDC.get("test.key"));
+ Assertions.assertEquals("value", org.jboss.logmanager.MDC.get("test.key"));
+ }
+
+ @Test
+ public void testNdc() {
+ NDC.push("value1");
+ NDC.push("value2");
+ final String expectedValue = "value1.value2";
+ Assertions.assertEquals(expectedValue, NDC.peek());
+ Assertions.assertEquals(expectedValue, NDC.get());
+ Assertions.assertEquals(2, NDC.getDepth());
+
+ // Test the log manager values
+ Assertions.assertEquals(expectedValue, org.jboss.logmanager.NDC.get());
+ Assertions.assertEquals(2, org.jboss.logmanager.NDC.getDepth());
+
+ // Pop the stack
+ Assertions.assertEquals("value2", NDC.pop());
+ Assertions.assertEquals(1, NDC.getDepth());
+ Assertions.assertEquals("value1", NDC.get());
+ Assertions.assertEquals("value1", org.jboss.logmanager.NDC.get());
+ Assertions.assertEquals(1, org.jboss.logmanager.NDC.getDepth());
+ }
+
+ @Override
+ void testLog(final Logger.Level level) {
+ final String msg = String.format("Test log message at %s", level);
+ logger.log(level, msg);
+
+ Assertions.assertTrue(logger.isEnabled(level), String.format("Logger not enabled for level %s", level));
+ testLog(msg, level);
+ }
+
+ @Override
+ void testLog(final String msg, final Logger.Level level) {
+ final LogRecord logRecord = handler.queue.poll();
+ Assertions.assertNotNull(logRecord, String.format("No record found for %s", level));
+ Assertions.assertEquals(level.name(), logRecord.getLevel().getName());
+ Assertions.assertEquals(msg, logRecord.getMessage());
+ }
+
+ @Override
+ Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return JBossLogManagerLogger.class;
+ }
+
+ private static TestHandler createHandler(final LogContext logContext, final String loggerName) {
+ final TestHandler handler = new TestHandler();
+ final java.util.logging.Logger julLogger = logContext.getLogger(loggerName);
+ julLogger.addHandler(handler);
+ julLogger.setLevel(Level.ALL);
+ return handler;
+ }
+
+ private static class TestHandler extends Handler {
+ final BlockingQueue<LogRecord> queue = new LinkedBlockingQueue<>();
+
+ @Override
+ public void publish(final LogRecord record) {
+ queue.add(record);
+ }
+
+ @Override
+ public void flush() {
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ queue.clear();
+ }
+ }
+}
=====================================
src/test/java/org/jboss/logging/JulClassPathTestCase.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class JulClassPathTestCase extends AbstractClassPathTestCase {
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return JDKLogger.class;
+ }
+}
=====================================
src/test/java/org/jboss/logging/JulProviderTestCase.java
=====================================
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class JulProviderTestCase extends AbstractLoggerTestCase {
+ private TestHandler handler;
+ private Logger logger;
+
+ @BeforeAll
+ public static void setup() {
+ System.setProperty("org.jboss.logging.provider", "jdk");
+ }
+
+ @BeforeEach
+ public void setupLogContext() {
+ logger = Logger.getLogger(getClass());
+ handler = createHandler(logger.getName());
+ }
+
+ @AfterEach
+ public void removeHandler() {
+ java.util.logging.Logger.getLogger(logger.getName()).removeHandler(handler);
+ handler.close();
+ }
+
+ @Test
+ public void testMdc() {
+ MDC.put("test.key", "value");
+ Assertions.assertEquals("value", MDC.get("test.key"));
+ }
+
+ @Test
+ public void testNdc() {
+ NDC.push("value1");
+ NDC.push("value2");
+ Assertions.assertEquals("value2", NDC.peek());
+ Assertions.assertEquals("value1 value2", NDC.get());
+ Assertions.assertEquals(2, NDC.getDepth());
+
+ // Pop the stack
+ Assertions.assertEquals("value2", NDC.pop());
+ Assertions.assertEquals(1, NDC.getDepth());
+ Assertions.assertEquals("value1", NDC.get());
+ }
+
+ @Override
+ void testLog(final Logger.Level level) {
+ final String msg = String.format("Test log message at %s", level);
+ logger.log(level, msg);
+
+ Assertions.assertTrue(logger.isEnabled(level), String.format("Logger not enabled for level %s", level));
+ testLog(msg, level);
+ }
+
+ @Override
+ void testLog(final String msg, final Logger.Level level) {
+ final LogRecord logRecord = handler.queue.poll();
+ Assertions.assertNotNull(logRecord, String.format("No record found for %s", level));
+ Assertions.assertEquals(level.name(), logRecord.getLevel().getName());
+ Assertions.assertEquals(msg, logRecord.getMessage());
+ }
+
+ @Override
+ Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return JDKLogger.class;
+ }
+
+ private static TestHandler createHandler(final String loggerName) {
+ final TestHandler handler = new TestHandler();
+ final java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(loggerName);
+ julLogger.addHandler(handler);
+ julLogger.setLevel(Level.ALL);
+ return handler;
+ }
+
+ private static class TestHandler extends Handler {
+ final BlockingQueue<LogRecord> queue = new LinkedBlockingQueue<>();
+
+ @Override
+ public void publish(final LogRecord record) {
+ queue.add(record);
+ }
+
+ @Override
+ public void flush() {
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ queue.clear();
+ }
+ }
+}
=====================================
src/test/java/org/jboss/logging/Log4j2ClassPathTestCase.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Log4j2ClassPathTestCase extends AbstractClassPathTestCase {
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Log4j2Logger.class;
+ }
+}
=====================================
src/test/java/org/jboss/logging/Log4j2ProviderTestCase.java
=====================================
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import java.io.Serializable;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Log4j2ProviderTestCase extends AbstractLoggerTestCase {
+ private TestAppender appender;
+ private Logger logger;
+
+ @BeforeAll
+ public static void setup() {
+ System.setProperty("org.jboss.logging.provider", "log4j2");
+ }
+
+ @BeforeEach
+ public void setupLogContext() {
+ logger = Logger.getLogger(getClass());
+ final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+ final Configuration config = ctx.getConfiguration();
+ appender = (TestAppender) config.getAppenders().get("TestAppender");
+ }
+
+ @Test
+ public void testMdc() {
+ MDC.put("test.key", "value");
+ Assertions.assertEquals("value", MDC.get("test.key"));
+ Assertions.assertEquals("value", ThreadContext.get("test.key"));
+ }
+
+ @Test
+ public void testNdc() {
+ NDC.push("value1");
+ NDC.push("value2");
+ Assertions.assertEquals("value2", NDC.peek());
+ // TODO (jrp) This is a weird case we should validate. NDC.get() does ThreadContext.peek() which doesn't seem
+ // TODO (jrp) correct. The method should likely do ThreadContext.getImmutableStack().toString(). At least that
+ // TODO (jrp) is what the NdcPatternConverter does.
+ //Assertions.assertEquals("[value1, value2]", NDC.get());
+ Assertions.assertEquals(2, NDC.getDepth());
+
+ // Test the log manager values
+ Assertions.assertEquals("[value1, value2]", ThreadContext.getImmutableStack().toString());
+ Assertions.assertEquals(2, ThreadContext.getDepth());
+
+ // Pop the stack
+ Assertions.assertEquals("value2", NDC.pop());
+ Assertions.assertEquals(1, NDC.getDepth());
+ Assertions.assertEquals("value1", NDC.get());
+ Assertions.assertEquals("value1", ThreadContext.peek());
+ Assertions.assertEquals(1, ThreadContext.getDepth());
+ }
+
+ @Override
+ void testLog(final Logger.Level level) {
+ final String msg = String.format("Test log message at %s", level);
+ logger.log(level, msg);
+
+ Assertions.assertTrue(logger.isEnabled(level), String.format("Logger not enabled for level %s", level));
+ testLog(msg, level);
+ }
+
+ @Override
+ void testLog(final String msg, final Logger.Level level) {
+ final LogEvent event = appender.queue.poll();
+ Assertions.assertNotNull(event, String.format("No record found for %s", level));
+ Assertions.assertEquals(level.name(), event.getLevel().toString());
+ Assertions.assertEquals(msg, event.getMessage().getFormattedMessage());
+ }
+
+ @Override
+ Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Log4j2Logger.class;
+ }
+
+ @SuppressWarnings("unused")
+ @Plugin(name = "TestAppender", category = "Core", elementType = "appender", printObject = true)
+ public static class TestAppender extends AbstractAppender {
+ final BlockingQueue<LogEvent> queue = new LinkedBlockingQueue<>();
+
+ protected TestAppender(String name, Filter filter, Layout<? extends Serializable> layout) {
+ super(name, filter, layout, false, null);
+ }
+
+ @Override
+ public void append(final LogEvent event) {
+ queue.add(event.toImmutable());
+ }
+
+ @Override
+ public void stop() {
+ queue.clear();
+ super.stop();
+ }
+
+ @PluginFactory
+ public static TestAppender createAppender(@PluginAttribute("name") String name,
+ @PluginElement("Layout") Layout<? extends Serializable> layout,
+ @PluginElement("Filter") final Filter filter,
+ @PluginAttribute("otherAttribute") String otherAttribute) {
+ if (name == null) {
+ LOGGER.error("No name provided for TestAppender");
+ return null;
+ }
+ if (layout == null) {
+ layout = PatternLayout.createDefaultLayout();
+ }
+ return new TestAppender(name, filter, layout);
+ }
+ }
+}
=====================================
src/test/java/org/jboss/logging/Log4jClassPathTestCase.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Log4jClassPathTestCase extends AbstractClassPathTestCase {
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Log4jLogger.class;
+ }
+}
=====================================
src/test/java/org/jboss/logging/Log4jProviderTestCase.java
=====================================
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Level;
+import org.apache.log4j.spi.LoggingEvent;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Log4jProviderTestCase extends AbstractLoggerTestCase {
+ private TestAppender appender;
+ private Logger logger;
+
+ @BeforeAll
+ public static void setup() {
+ System.setProperty("org.jboss.logging.provider", "log4j");
+ }
+
+ @BeforeEach
+ public void setupLogContext() {
+ logger = Logger.getLogger(getClass());
+ appender = createAppender(logger.getName());
+ }
+
+ @AfterEach
+ public void removeAppender() {
+ org.apache.log4j.Logger.getLogger(logger.getName()).removeAppender(appender);
+ appender.close();
+ }
+
+ @Test
+ public void testMdc() {
+ MDC.put("test.key", "value");
+ Assertions.assertEquals("value", MDC.get("test.key"));
+ Assertions.assertEquals("value", org.apache.log4j.MDC.get("test.key"));
+ }
+
+ @Test
+ public void testNdc() {
+ NDC.push("value1");
+ NDC.push("value2");
+ Assertions.assertEquals("value2", NDC.peek());
+ Assertions.assertEquals("value1 value2", NDC.get());
+ Assertions.assertEquals(2, NDC.getDepth());
+
+ // Test the log manager values
+ Assertions.assertEquals("value1 value2", org.apache.log4j.NDC.get());
+ Assertions.assertEquals(2, org.apache.log4j.NDC.getDepth());
+
+ // Pop the stack
+ Assertions.assertEquals("value2", NDC.pop());
+ Assertions.assertEquals(1, NDC.getDepth());
+ Assertions.assertEquals("value1", NDC.get());
+ Assertions.assertEquals("value1", org.apache.log4j.NDC.get());
+ Assertions.assertEquals(1, org.apache.log4j.NDC.getDepth());
+ }
+
+ @Override
+ void testLog(final Logger.Level level) {
+ final String msg = String.format("Test log message at %s", level);
+ logger.log(level, msg);
+
+ Assertions.assertTrue(logger.isEnabled(level), String.format("Logger not enabled for level %s", level));
+ testLog(msg, level);
+ }
+
+ @Override
+ void testLog(final String msg, final Logger.Level level) {
+ final LoggingEvent event = appender.queue.poll();
+ Assertions.assertNotNull(event, String.format("No record found for %s", level));
+ Assertions.assertEquals(level.name(), event.getLevel().toString());
+ Assertions.assertEquals(msg, event.getMessage());
+ }
+
+ @Override
+ Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Log4jLogger.class;
+ }
+
+ private static TestAppender createAppender(final String loggerName) {
+ final TestAppender appender = new TestAppender();
+ final org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(loggerName);
+ log4jLogger.addAppender(appender);
+ log4jLogger.setLevel(Level.ALL);
+ return appender;
+ }
+
+ private static class TestAppender extends AppenderSkeleton {
+ final BlockingQueue<LoggingEvent> queue = new LinkedBlockingQueue<>();
+
+ @Override
+ protected void append(final LoggingEvent loggingEvent) {
+ queue.add(loggingEvent);
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ queue.clear();
+ }
+
+ @Override
+ public boolean requiresLayout() {
+ return false;
+ }
+ }
+}
=====================================
src/test/java/org/jboss/logging/Slf4jClassPathTestCase.java
=====================================
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Slf4jClassPathTestCase extends AbstractClassPathTestCase {
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Slf4jLocationAwareLogger.class;
+ }
+}
=====================================
src/test/java/org/jboss/logging/Slf4jProviderTestCase.java
=====================================
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ *
+ * Copyright 2020 Red Hat, Inc.
+ *
+ * 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.jboss.logging;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author <a href="mailto:jperkins at redhat.com">James R. Perkins</a>
+ */
+public class Slf4jProviderTestCase extends AbstractLoggerTestCase {
+ private TestAppender appender;
+ private Logger logger;
+
+ @BeforeAll
+ public static void setup() {
+ System.setProperty("org.jboss.logging.provider", "slf4j");
+ }
+
+ @BeforeEach
+ public void setupLogContext() {
+ logger = Logger.getLogger(getClass());
+ appender = createHandler(logger.getName());
+ }
+
+ @AfterEach
+ public void removeAppender() {
+ ch.qos.logback.classic.Logger lbLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(logger.getName());
+ lbLogger.detachAppender(appender);
+ appender.stop();
+ }
+
+ @Test
+ public void testMdc() {
+ MDC.put("test.key", "value");
+ Assertions.assertEquals("value", MDC.get("test.key"));
+ Assertions.assertEquals("value", org.slf4j.MDC.get("test.key"));
+ }
+
+ @Test
+ public void testNdc() {
+ NDC.push("value1");
+ NDC.push("value2");
+ Assertions.assertEquals("value2", NDC.peek());
+ Assertions.assertEquals("value1 value2", NDC.get());
+ Assertions.assertEquals(2, NDC.getDepth());
+
+ // Pop the stack
+ Assertions.assertEquals("value2", NDC.pop());
+ Assertions.assertEquals(1, NDC.getDepth());
+ Assertions.assertEquals("value1", NDC.get());
+ }
+
+ @Override
+ void testLog(final Logger.Level level) {
+ final String msg = String.format("Test log message at %s", level);
+ logger.log(level, msg);
+
+ Assertions.assertTrue(logger.isEnabled(level), String.format("Logger not enabled for level %s", level));
+ testLog(msg, level);
+ }
+
+ @Override
+ void testLog(final String msg, final Logger.Level level) {
+ final ILoggingEvent event = appender.queue.poll();
+ Assertions.assertNotNull(event, String.format("No record found for %s", level));
+ final Logger.Level translatedLevel = level == Logger.Level.FATAL ? Logger.Level.ERROR : level;
+ Assertions.assertEquals(translatedLevel.name(), event.getLevel().toString());
+ Assertions.assertEquals(msg, event.getFormattedMessage());
+ }
+
+ @Override
+ Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ Class<? extends Logger> getLoggerClass() {
+ return Slf4jLocationAwareLogger.class;
+ }
+
+ private static TestAppender createHandler(final String loggerName) {
+ final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
+ final TestAppender appender = new TestAppender();
+ appender.setContext(context);
+ appender.start();
+
+ ch.qos.logback.classic.Logger lbLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(loggerName);
+ lbLogger.addAppender(appender);
+ lbLogger.setLevel(Level.ALL);
+ return appender;
+ }
+
+ public static class TestAppender extends AppenderBase<ILoggingEvent> {
+ final BlockingQueue<ILoggingEvent> queue = new LinkedBlockingQueue<>();
+
+ @Override
+ protected void append(final ILoggingEvent event) {
+ queue.add(event);
+ }
+ }
+}
=====================================
src/test/resources/META-INF/services/org.jboss.logging.LoggerProvider
=====================================
@@ -0,0 +1 @@
+org.jboss.logging.CustomProviderTestCase$TestProvider
\ No newline at end of file
=====================================
src/test/resources/log4j2-test.xml
=====================================
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~
+ ~ Copyright 2020 Red Hat, Inc.
+ ~
+ ~ 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.
+ -->
+
+<Configuration status="WARN" packages="org.jboss.logging">
+ <Appenders>
+ <TestAppender name="TestAppender">
+ <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+ </TestAppender>
+ </Appenders>
+ <Loggers>
+ <Logger name="org.jboss.logging.Log4j2ProviderTestCase" level="All">
+ <AppenderRef ref="TestAppender" level="All"/>
+ </Logger>
+ </Loggers>
+</Configuration>
\ No newline at end of file
View it on GitLab: https://salsa.debian.org/java-team/jboss-logging/-/compare/ca7ca3ae1ef6a8eb406a7fb6ae38d35666bd7f7b...3c72bbae3eba4278e5078ecbd31eaf6816c84c58
--
View it on GitLab: https://salsa.debian.org/java-team/jboss-logging/-/compare/ca7ca3ae1ef6a8eb406a7fb6ae38d35666bd7f7b...3c72bbae3eba4278e5078ecbd31eaf6816c84c58
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/20210925/ff83aec4/attachment.htm>
More information about the pkg-java-commits
mailing list