LOG4J2-2305 - rename module. Add to distribution
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/922fefdc Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/922fefdc Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/922fefdc Branch: refs/heads/release-2.x Commit: 922fefdc7265b110d1a00916630acb786104f2db Parents: af5cd99 Author: Ralph Goers <[email protected]> Authored: Thu Jul 5 07:05:17 2018 -0700 Committer: Ralph Goers <[email protected]> Committed: Thu Jul 5 07:05:17 2018 -0700 ---------------------------------------------------------------------- log4j-distribution/pom.xml | 17 ++ log4j-slf4j18-impl/pom.xml | 259 +++++++++++++++++++ .../logging/slf4j/SLF4JServiceProvider.java | 57 ++++ .../services/org.slf4j.spi.SLF4JServiceProvider | 1 + log4j-slf4j18-impl/src/site/markdown/index.md | 40 +++ log4j-slf4j18-impl/src/site/site.xml | 52 ++++ .../logging/slf4j/CallerInformationTest.java | 67 +++++ .../apache/logging/slf4j/CustomFlatMarker.java | 76 ++++++ .../org/apache/logging/slf4j/Log4j1222Test.java | 57 ++++ .../logging/slf4j/Log4j2_1482_Slf4jTest.java | 41 +++ .../apache/logging/slf4j/Log4jMarkerTest.java | 38 +++ .../org/apache/logging/slf4j/LoggerTest.java | 182 +++++++++++++ .../org/apache/logging/slf4j/MarkerTest.java | 178 +++++++++++++ .../org/apache/logging/slf4j/OptionalTest.java | 69 +++++ .../org/apache/logging/slf4j/SerializeTest.java | 46 ++++ .../src/test/resources/log4j-test1.xml | 40 +++ .../src/test/resources/log4j2-1482.xml | 27 ++ log4j-slf4j18/pom.xml | 259 ------------------- .../logging/slf4j/SLF4JServiceProvider.java | 57 ---- .../services/org.slf4j.spi.SLF4JServiceProvider | 1 - log4j-slf4j18/src/site/markdown/index.md | 40 --- log4j-slf4j18/src/site/site.xml | 52 ---- .../logging/slf4j/CallerInformationTest.java | 67 ----- .../apache/logging/slf4j/CustomFlatMarker.java | 76 ------ .../org/apache/logging/slf4j/Log4j1222Test.java | 57 ---- .../logging/slf4j/Log4j2_1482_Slf4jTest.java | 41 --- .../apache/logging/slf4j/Log4jMarkerTest.java | 38 --- .../org/apache/logging/slf4j/LoggerTest.java | 182 ------------- .../org/apache/logging/slf4j/MarkerTest.java | 178 ------------- .../org/apache/logging/slf4j/OptionalTest.java | 69 ----- .../org/apache/logging/slf4j/SerializeTest.java | 46 ---- .../src/test/resources/log4j-test1.xml | 40 --- .../src/test/resources/log4j2-1482.xml | 27 -- pom.xml | 4 +- 34 files changed, 1249 insertions(+), 1232 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-distribution/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-distribution/pom.xml b/log4j-distribution/pom.xml index 0ae8cf8..56ddc59 100644 --- a/log4j-distribution/pom.xml +++ b/log4j-distribution/pom.xml @@ -172,6 +172,23 @@ </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j18-impl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j18-impl</artifactId> + <version>${project.version}</version> + <classifier>sources</classifier> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j18-impl</artifactId> + <version>${project.version}</version> + <classifier>javadoc</classifier> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/pom.xml b/log4j-slf4j18-impl/pom.xml new file mode 100644 index 0000000..f1fb21e --- /dev/null +++ b/log4j-slf4j18-impl/pom.xml @@ -0,0 +1,259 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j</artifactId> + <version>2.11.1-SNAPSHOT</version> + <relativePath>../</relativePath> + </parent> + <artifactId>log4j-slf4j18-impl</artifactId> + <packaging>jar</packaging> + <name>Apache Log4j SLF4J 1.8+ Binding</name> + <description>The Apache Log4j SLF4J 1.8 API binding to Log4j 2 Core</description> + <properties> + <log4jParentDir>${basedir}/..</log4jParentDir> + <docLabel>SLF4J Documentation</docLabel> + <projectDir>/slf4j18</projectDir> + <slf4j.version>1.8.0-alpha2</slf4j.version> + <module.name>org.apache.logging.log4j.slf4j</module.name> + </properties> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-ext</artifactId> + <version>${slf4j.version}</version> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>provided</scope> + <type>zip</type> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-csv</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>3.0.2</version> + <executions> + <execution> + <id>unpack-classes</id> + <phase>process-resources</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>${project.version}</version> + <type>zip</type> + <overWrite>false</overWrite> + </artifactItem> + </artifactItems> + <includes>**/*.class</includes> + <excludes>**/*.java</excludes> + <outputDirectory>${project.build.directory}</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + </configuration> + </execution> + </executions> + </plugin> + <!-- Include the standard NOTICE and LICENSE --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-remote-resources-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>process</goal> + </goals> + <configuration> + <skip>false</skip> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Export-Package> + org.apache.logging.slf4j, + org.slf4j.impl + </Export-Package> + <Require-Capability> + osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)" + </Require-Capability> + <Provide-Capability> + osgi.serviceloader;osgi.serviceloader=org.slf4j.spi.SLF4JServiceProvider + </Provide-Capability> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-changes-plugin</artifactId> + <version>${changes.plugin.version}</version> + <reportSets> + <reportSet> + <reports> + <report>changes-report</report> + </reports> + </reportSet> + </reportSets> + <configuration> + <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate> + <useJql>true</useJql> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>${checkstyle.plugin.version}</version> + <configuration> + <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> --> + <configLocation>${log4jParentDir}/checkstyle.xml</configLocation> + <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation> + <enableRulesSummary>false</enableRulesSummary> + <propertyExpansion>basedir=${basedir}</propertyExpansion> + <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>${javadoc.plugin.version}</version> + <configuration> + <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br /> + Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, + and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom> + <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating + project --> + <detectOfflineLinks>false</detectOfflineLinks> + <linksource>true</linksource> + </configuration> + <reportSets> + <reportSet> + <id>non-aggregate</id> + <reports> + <report>javadoc</report> + </reports> + </reportSet> + </reportSets> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>findbugs-maven-plugin</artifactId> + <version>${findbugs.plugin.version}</version> + <configuration> + <fork>true</fork> + <jvmArgs>-Duser.language=en</jvmArgs> + <threshold>Normal</threshold> + <effort>Default</effort> + <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + <version>${jxr.plugin.version}</version> + <reportSets> + <reportSet> + <id>non-aggregate</id> + <reports> + <report>jxr</report> + </reports> + </reportSet> + <reportSet> + <id>aggregate</id> + <reports> + <report>aggregate</report> + </reports> + </reportSet> + </reportSets> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + <version>${pmd.plugin.version}</version> + <configuration> + <targetJdk>${maven.compiler.target}</targetJdk> + </configuration> + </plugin> + </plugins> + </reporting> +</project> + http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java new file mode 100644 index 0000000..332d16d --- /dev/null +++ b/log4j-slf4j18-impl/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import org.slf4j.ILoggerFactory; +import org.slf4j.IMarkerFactory; +import org.slf4j.spi.MDCAdapter; + +public class SLF4JServiceProvider implements org.slf4j.spi.SLF4JServiceProvider { + + public static final String REQUESTED_API_VERSION = "1.8.99"; + + private ILoggerFactory loggerFactory; + private IMarkerFactory markerFactory; + private MDCAdapter mdcAdapter; + + @Override + public ILoggerFactory getLoggerFactory() { + return loggerFactory; + } + + @Override + public IMarkerFactory getMarkerFactory() { + return markerFactory; + } + + @Override + public MDCAdapter getMDCAdapter() { + return mdcAdapter; + } + + @Override + public String getRequesteApiVersion() { + return REQUESTED_API_VERSION; + } + + @Override + public void initialize() { + loggerFactory = new Log4jLoggerFactory(); + markerFactory = new Log4jMarkerFactory(); + mdcAdapter = new Log4jMDCAdapter(); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider b/log4j-slf4j18-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider new file mode 100644 index 0000000..1577f12 --- /dev/null +++ b/log4j-slf4j18-impl/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider @@ -0,0 +1 @@ +org.apache.logging.slf4j.SLF4JServiceProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/site/markdown/index.md b/log4j-slf4j18-impl/src/site/markdown/index.md new file mode 100644 index 0000000..6e3f3f6 --- /dev/null +++ b/log4j-slf4j18-impl/src/site/markdown/index.md @@ -0,0 +1,40 @@ +<!-- vim: set syn=markdown : --> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +# Log4j 2 SLF4J Binding + +The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use +Log4j 2 as the implementation. + +## Requirements + +The Log4j 2 SLF4J Binding has a dependency on the Log4j 2 API as well as the SLF4J API. +For more information, see [Runtime Dependencies](../runtime-dependencies.html). + +## Usage + +The SLF4J binding provided in this component cause all the SLF4J APIs to be routed to Log4j 2. Simply +include the Log4j 2 SLF4J Binding jar along with the Log4j 2 jars and SLF4J API jar to cause all SLF4J +logging to be handled by Log4j 2. + +<div class="alert alert-danger"> +Use of the Log4j 2 SLF4J Binding (log4j-slf4j-impl-2.0.jar) together with +the SLF4J adapter (log4j-to-slf4j-2.0.jar) should +never be attempted, as it will cause events to endlessly be routed between +SLF4J and Log4j 2. +</div> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/site/site.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/site/site.xml b/log4j-slf4j18-impl/src/site/site.xml new file mode 100644 index 0000000..a1f9106 --- /dev/null +++ b/log4j-slf4j18-impl/src/site/site.xml @@ -0,0 +1,52 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + +--> +<project name="SLF4J Binding Using Log4j" + xmlns="http://maven.apache.org/DECORATION/1.4.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> + <body> + <links> + <item name="Apache" href="http://www.apache.org/" /> + <item name="Logging Services" href="http://logging.apache.org/"/> + <item name="Log4j" href="../index.html"/> + </links> + + <!-- Component-specific reports --> + <menu ref="reports"/> + + <!-- Overall Project Info --> + <menu name="Log4j Project Information" img="icon-info-sign"> + <item name="Dependencies" href="../dependencies.html" /> + <item name="Dependency Convergence" href="../dependency-convergence.html" /> + <item name="Dependency Management" href="../dependency-management.html" /> + <item name="Project Team" href="../team-list.html" /> + <item name="Mailing Lists" href="../mail-lists.html" /> + <item name="Issue Tracking" href="../issue-tracking.html" /> + <item name="Project License" href="../license.html" /> + <item name="Source Repository" href="../source-repository.html" /> + <item name="Project Summary" href="../project-summary.html" /> + </menu> + + <menu name="Log4j Project Reports" img="icon-cog"> + <item name="Changes Report" href="../changes-report.html" /> + <item name="JIRA Report" href="../jira-report.html" /> + <item name="Surefire Report" href="../surefire-report.html" /> + <item name="RAT Report" href="../rat-report.html" /> + </menu> + </body> +</project> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java new file mode 100644 index 0000000..7efc0e5 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CallerInformationTest { + + // config from log4j-core test-jar + private static final String CONFIG = "log4j2-calling-class.xml"; + + @ClassRule + public static final LoggerContextRule ctx = new LoggerContextRule(CONFIG); + + @Test + public void testClassLogger() throws Exception { + final ListAppender app = ctx.getListAppender("Class").clear(); + final Logger logger = LoggerFactory.getLogger("ClassLogger"); + logger.info("Ignored message contents."); + logger.warn("Verifying the caller class is still correct."); + logger.error("Hopefully nobody breaks me!"); + final List<String> messages = app.getMessages(); + assertEquals("Incorrect number of messages.", 3, messages.size()); + for (final String message : messages) { + assertEquals("Incorrect caller class name.", this.getClass().getName(), message); + } + } + + @Test + public void testMethodLogger() throws Exception { + final ListAppender app = ctx.getListAppender("Method").clear(); + final Logger logger = LoggerFactory.getLogger("MethodLogger"); + logger.info("More messages."); + logger.warn("CATASTROPHE INCOMING!"); + logger.error("ZOMBIES!!!"); + logger.warn("brains~~~"); + logger.info("Itchy. Tasty."); + final List<String> messages = app.getMessages(); + assertEquals("Incorrect number of messages.", 5, messages.size()); + for (final String message : messages) { + assertEquals("Incorrect caller method name.", "testMethodLogger", message); + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java new file mode 100644 index 0000000..0138cea --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import java.util.Iterator; + +import org.slf4j.Marker; + +/** + * Test Marker that may contain no reference/parent Markers. + * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-793">LOG4J2-793</a> + */ +public class CustomFlatMarker implements Marker { + private static final long serialVersionUID = -4115520883240247266L; + + private final String name; + + public CustomFlatMarker(final String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public void add(final Marker reference) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(final Marker reference) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasChildren() { + return hasReferences(); + } + + @Override + public boolean hasReferences() { + return false; + } + + @Override + public Iterator<Marker> iterator() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean contains(final Marker other) { + return false; + } + + @Override + public boolean contains(final String name) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java new file mode 100644 index 0000000..59f69e0 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.*; + +/** + * Tests logging during shutdown. + */ +public class Log4j1222Test +{ + + @Test + public void homepageRendersSuccessfully() + { + System.setProperty("log4j.configurationFile", "log4j2-console.xml"); + Runtime.getRuntime().addShutdownHook(new ShutdownHook()); + } + + private static class ShutdownHook extends Thread { + + private static class Holder { + private static final Logger LOGGER = LoggerFactory.getLogger(Log4j1222Test.class); + } + + @Override + public void run() + { + super.run(); + trigger(); + } + + private void trigger() { + Holder.LOGGER.info("Attempt to trigger"); + assertTrue("Logger is of type " + Holder.LOGGER.getClass().getName(), Holder.LOGGER instanceof Log4jLogger); + + } + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java new file mode 100644 index 0000000..8934f29 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import org.apache.logging.log4j.core.layout.Log4j2_1482_Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Tests https://issues.apache.org/jira/browse/LOG4J2-1482 + */ +public class Log4j2_1482_Slf4jTest extends Log4j2_1482_Test { + + @Override + protected void log(final int runNumber) { + if (runNumber == 2) { + // System.out.println("Set a breakpoint here."); + } + final Logger logger = LoggerFactory.getLogger("auditcsvfile"); + final int val1 = 9, val2 = 11, val3 = 12; + logger.info("Info Message!", val1, val2, val3); + logger.info("Info Message!", val1, val2, val3); + logger.info("Info Message!", val1, val2, val3); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java new file mode 100644 index 0000000..af7c394 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.junit.Assert; +import org.junit.Test; + +public class Log4jMarkerTest { + + @Test + public void testEquals() { + final Marker markerA = MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-A"); + final Marker markerB = MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-B"); + final Log4jMarker marker1 = new Log4jMarker(markerA); + final Log4jMarker marker2 = new Log4jMarker(markerA); + final Log4jMarker marker3 = new Log4jMarker(markerB); + Assert.assertEquals(marker1, marker2); + Assert.assertNotEquals(marker1, null); + Assert.assertNotEquals(null, marker1); + Assert.assertNotEquals(marker1, marker3); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java new file mode 100644 index 0000000..0524074 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Locale; + +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.apache.logging.log4j.util.Strings; +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.ext.EventData; +import org.slf4j.ext.EventLogger; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; +import org.slf4j.spi.LocationAwareLogger; + +/** + * + */ +public class LoggerTest { + + private static final String CONFIG = "log4j-test1.xml"; + + @ClassRule + public static LoggerContextRule ctx = new LoggerContextRule(CONFIG); + + Logger logger = LoggerFactory.getLogger("LoggerTest"); + XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest"); + + @Test + public void basicFlow() { + xlogger.entry(); + verify("List", "o.a.l.s.LoggerTest entry MDC{}" + Strings.LINE_SEPARATOR); + xlogger.exit(); + verify("List", "o.a.l.s.LoggerTest exit MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void simpleFlow() { + xlogger.entry(CONFIG); + verify("List", "o.a.l.s.LoggerTest entry with (log4j-test1.xml) MDC{}" + Strings.LINE_SEPARATOR); + xlogger.exit(0); + verify("List", "o.a.l.s.LoggerTest exit with (0) MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void throwing() { + xlogger.throwing(new IllegalArgumentException("Test Exception")); + verify("List", "o.a.l.s.LoggerTest throwing MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void catching() { + try { + throw new NullPointerException(); + } catch (final Exception e) { + xlogger.catching(e); + verify("List", "o.a.l.s.LoggerTest catching MDC{}" + Strings.LINE_SEPARATOR); + } + } + + @Test + public void debug() { + logger.debug("Debug message"); + verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void debugNoParms() { + logger.debug("Debug message {}"); + verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR); + logger.debug("Debug message {}", (Object[]) null); + verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR); + ((LocationAwareLogger)logger).log(null, Log4jLogger.class.getName(), LocationAwareLogger.DEBUG_INT, + "Debug message {}", null, null); + verify("List", "o.a.l.s.LoggerTest Debug message {} MDC{}" + Strings.LINE_SEPARATOR); + } + + + @Test + public void debugWithParms() { + logger.debug("Hello, {}", "World"); + verify("List", "o.a.l.s.LoggerTest Hello, World MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void mdc() { + + MDC.put("TestYear", "2010"); + logger.debug("Debug message"); + verify("List", "o.a.l.s.LoggerTest Debug message MDC{TestYear=2010}" + Strings.LINE_SEPARATOR); + MDC.clear(); + logger.debug("Debug message"); + verify("List", "o.a.l.s.LoggerTest Debug message MDC{}" + Strings.LINE_SEPARATOR); + } + + /** + * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-793">LOG4J2-793</a> + */ + @Test + public void supportsCustomSLF4JMarkers() { + final Marker marker = new CustomFlatMarker("TEST"); + logger.debug(marker, "Test"); + verify("List", "o.a.l.s.LoggerTest Test MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void testRootLogger() { + final Logger l = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + assertNotNull("No Root Logger", l); + assertEquals(Logger.ROOT_LOGGER_NAME, l.getName()); + } + + @Test + public void doubleSubst() { + logger.debug("Hello, {}", "Log4j {}"); + verify("List", "o.a.l.s.LoggerTest Hello, Log4j {} MDC{}" + Strings.LINE_SEPARATOR); + xlogger.debug("Hello, {}", "Log4j {}"); + verify("List", "o.a.l.s.LoggerTest Hello, Log4j Log4j {} MDC{}" + Strings.LINE_SEPARATOR); + } + + @Test + public void testEventLogger() { + MDC.put("loginId", "JohnDoe"); + MDC.put("ipAddress", "192.168.0.120"); + MDC.put("locale", Locale.US.getDisplayName()); + final EventData data = new EventData(); + data.setEventType("Transfer"); + data.setEventId("Audit@18060"); + data.setMessage("Transfer Complete"); + data.put("ToAccount", "123456"); + data.put("FromAccount", "123457"); + data.put("Amount", "200.00"); + EventLogger.logEvent(data); + MDC.clear(); + verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Strings.LINE_SEPARATOR); + } + + private void verify(final String name, final String expected) { + final ListAppender listApp = ctx.getListAppender(name); + assertNotNull("Missing Appender", listApp); + final List<String> events = listApp.getMessages(); + assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1); + final String actual = events.get(0); + assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual); + listApp.clear(); + } + + @Before + @After + public void cleanup() { + MDC.clear(); + ctx.getListAppender("List").clear(); + ctx.getListAppender("EventLogger").clear(); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java new file mode 100644 index 0000000..6ef3846 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/MarkerTest.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * + */ +public class MarkerTest { + + private static final String CHILD_MAKER_NAME = MarkerTest.class.getSimpleName() + "-TEST"; + private static final String PARENT_MARKER_NAME = MarkerTest.class.getSimpleName() + "-PARENT"; + + @Before + @After + public void clearMarkers() { + MarkerManager.clear(); + } + + @Test + public void testAddMarker() { + final String childMakerName = CHILD_MAKER_NAME + "-AM"; + final String parentMarkerName = PARENT_MARKER_NAME + "-AM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMarkerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMarkerName); + final Marker log4jMarker = MarkerManager.getMarker(childMakerName); + + assertTrue("Incorrect Marker class", slf4jMarker instanceof Log4jMarker); + assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j", + childMakerName, parentMarkerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent)); + assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J", + childMakerName, parentMarkerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent)); + } + + @Test + public void testAddNullMarker() { + final String childMarkerName = CHILD_MAKER_NAME + "-ANM"; + final String parentMakerName = PARENT_MARKER_NAME + "-ANM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); + final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); + final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); + final org.slf4j.Marker nullMarker = null; + try { + log4jSlf4jParent.add(nullMarker); + fail("Expected " + IllegalArgumentException.class.getName()); + } catch (final IllegalArgumentException e) { + // expected + } + try { + log4jSlf4jMarker.add(nullMarker); + fail("Expected " + IllegalArgumentException.class.getName()); + } catch (final IllegalArgumentException e) { + // expected + } + } + + @Test + public void testAddSameMarker() { + final String childMarkerName = CHILD_MAKER_NAME + "-ASM"; + final String parentMakerName = PARENT_MARKER_NAME + "-ASM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); + assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j", + childMarkerName, parentMakerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent)); + assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J", + childMarkerName, parentMakerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent)); + } + + @Test + public void testEquals() { + final String childMarkerName = CHILD_MAKER_NAME + "-ASM"; + final String parentMakerName = PARENT_MARKER_NAME + "-ASM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jMarker2 = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); + final Marker log4jMarker2 = MarkerManager.getMarker(childMarkerName); + assertEquals(log4jParent, log4jParent); + assertEquals(log4jMarker, log4jMarker); + assertEquals(log4jMarker, log4jMarker2); + assertEquals(slf4jMarker, slf4jMarker2); + assertNotEquals(log4jParent, log4jMarker); + assertNotEquals(log4jMarker, log4jParent); + } + + @Test + public void testContainsNullMarker() { + final String childMarkerName = CHILD_MAKER_NAME + "-CM"; + final String parentMakerName = PARENT_MARKER_NAME + "-CM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); + final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); + final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); + final org.slf4j.Marker nullMarker = null; + try { + Assert.assertFalse(log4jSlf4jParent.contains(nullMarker)); + fail("Expected " + IllegalArgumentException.class.getName()); + } catch (final IllegalArgumentException e) { + // expected + } + try { + Assert.assertFalse(log4jSlf4jMarker.contains(nullMarker)); + fail("Expected " + IllegalArgumentException.class.getName()); + } catch (final IllegalArgumentException e) { + // expected + } + } + + @Test + public void testContainsNullString() { + final String childMarkerName = CHILD_MAKER_NAME + "-CS"; + final String parentMakerName = PARENT_MARKER_NAME + "-CS"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMarkerName); + final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); + final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); + final String nullStr = null; + Assert.assertFalse(log4jSlf4jParent.contains(nullStr)); + Assert.assertFalse(log4jSlf4jMarker.contains(nullStr)); + } + + @Test + public void testRemoveNullMarker() { + final String childMakerName = CHILD_MAKER_NAME + "-CM"; + final String parentMakerName = PARENT_MARKER_NAME + "-CM"; + final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName); + final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName); + slf4jMarker.add(slf4jParent); + final Marker log4jParent = MarkerManager.getMarker(parentMakerName); + final Marker log4jMarker = MarkerManager.getMarker(childMakerName); + final Log4jMarker log4jSlf4jParent = new Log4jMarker(log4jParent); + final Log4jMarker log4jSlf4jMarker = new Log4jMarker(log4jMarker); + final org.slf4j.Marker nullMarker = null; + Assert.assertFalse(log4jSlf4jParent.remove(nullMarker)); + Assert.assertFalse(log4jSlf4jMarker.remove(nullMarker)); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java new file mode 100644 index 0000000..a6e9fd5 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/OptionalTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import java.util.List; + +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.apache.logging.log4j.util.Strings; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +import static org.junit.Assert.*; + +/** + * + */ +public class OptionalTest { + + private static final String CONFIG = "log4j-test1.xml"; + + @ClassRule + public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG); + + Logger logger = LoggerFactory.getLogger("EventLogger"); + Marker marker = MarkerFactory.getMarker("EVENT"); + + @Test + public void testEventLogger() { + logger.info(marker, "This is a test"); + MDC.clear(); + verify("EventLogger", "o.a.l.s.OptionalTest This is a test" + Strings.LINE_SEPARATOR); + } + + private void verify(final String name, final String expected) { + final ListAppender listApp = CTX.getListAppender(name); + final List<String> events = listApp.getMessages(); + assertTrue("Incorrect number of messages. Expected 1 Actual " + events.size(), events.size()== 1); + final String actual = events.get(0); + assertEquals("Incorrect message. Expected " + expected + ". Actual " + actual, expected, actual); + listApp.clear(); + } + + @Before + public void cleanup() { + CTX.getListAppender("List").clear(); + CTX.getListAppender("EventLogger").clear(); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/SerializeTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/SerializeTest.java b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/SerializeTest.java new file mode 100644 index 0000000..d3d3db6 --- /dev/null +++ b/log4j-slf4j18-impl/src/test/java/org/apache/logging/slf4j/SerializeTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.logging.slf4j; + +import java.io.Serializable; + +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.logging.log4j.SerializableMatchers.serializesRoundTrip; +import static org.junit.Assert.*; + +/** + * + */ +public class SerializeTest { + + private static final String CONFIG = "log4j-test1.xml"; + + @ClassRule + public static final LoggerContextRule CTX = new LoggerContextRule(CONFIG); + + Logger logger = LoggerFactory.getLogger("LoggerTest"); + + @Test + public void testLogger() throws Exception { + assertThat((Serializable) logger, serializesRoundTrip()); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml b/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml new file mode 100644 index 0000000..a64bdfa --- /dev/null +++ b/log4j-slf4j18-impl/src/test/resources/log4j-test1.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration status="error" name="LoggerTest"> + <properties> + <property name="filename">target/test.log</property> + </properties> + <ThresholdFilter level="trace"/> + + <Appenders> + <List name="EventLogger"> + <PatternLayout pattern="%C{1.} %m%n"/> + </List> + <Console name="STDOUT"> + <PatternLayout pattern="%C{1.} %m MDC%X%n"/> + </Console> + <File name="File" fileName="${filename}"> + <PatternLayout> + <pattern>%d %p %C{1.} [%t] %m%n</pattern> + </PatternLayout> + </File> + <List name="List"> + <PatternLayout pattern="%C{1.} %m MDC%X%n%ex{0}"/> + </List> + <SLF4J name="SLF4J"/> + </Appenders> + + <Loggers> + <Logger name="EventLogger" level="info" additivity="false"> + <AppenderRef ref="EventLogger"/> + </Logger>> + + <Logger name="org.apache.logging.log4j.test2" level="debug" additivity="false"> + <AppenderRef ref="File"/> + </Logger> + + <Root level="trace"> + <AppenderRef ref="List"/> + </Root> + </Loggers> + +</configuration> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18-impl/src/test/resources/log4j2-1482.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18-impl/src/test/resources/log4j2-1482.xml b/log4j-slf4j18-impl/src/test/resources/log4j2-1482.xml new file mode 100644 index 0000000..e17953c --- /dev/null +++ b/log4j-slf4j18-impl/src/test/resources/log4j2-1482.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration status="warn" name="MyApp" packages=""> + <Properties> + <Property name="audit-path">target/log4j2-1482</Property> + <Property name="file-name">audit</Property> + <Property name="file-header">param1,param2,param3${sys:line.separator} + </Property> + </Properties> + + <Appenders> + <RollingFile name="auditfile" fileName="${audit-path}/${file-name}.tmp" + filePattern="${audit-path}/${file-name}-%d{yyyy-MM-dd}-%i.csv"> + <CsvParameterLayout delimiter="," header="${file-header}"> + </CsvParameterLayout> + <Policies> + <SizeBasedTriggeringPolicy size="80 B" /> + </Policies> + <DefaultRolloverStrategy max="2" /> + </RollingFile> + </Appenders> + + <Loggers> + <Root level="info"> + <AppenderRef ref="auditfile" /> + </Root> + </Loggers> +</Configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/pom.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/pom.xml b/log4j-slf4j18/pom.xml deleted file mode 100644 index 1d788cf..0000000 --- a/log4j-slf4j18/pom.xml +++ /dev/null @@ -1,259 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j</artifactId> - <version>2.11.1-SNAPSHOT</version> - <relativePath>../</relativePath> - </parent> - <artifactId>log4j-slf4j18</artifactId> - <packaging>jar</packaging> - <name>Apache Log4j SLF4J 1.8+ Binding</name> - <description>The Apache Log4j SLF4J 1.8 API binding to Log4j 2 Core</description> - <properties> - <log4jParentDir>${basedir}/..</log4jParentDir> - <docLabel>SLF4J Documentation</docLabel> - <projectDir>/slf4j18</projectDir> - <slf4j.version>1.8.0-alpha2</slf4j.version> - <module.name>org.apache.logging.log4j.slf4j</module.name> - </properties> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>${slf4j.version}</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-ext</artifactId> - <version>${slf4j.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <scope>provided</scope> - <type>zip</type> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-api</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-csv</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-core</artifactId> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>3.0.2</version> - <executions> - <execution> - <id>unpack-classes</id> - <phase>process-resources</phase> - <goals> - <goal>unpack</goal> - </goals> - <configuration> - <artifactItems> - <artifactItem> - <groupId>org.apache.logging.log4j</groupId> - <artifactId>log4j-slf4j-impl</artifactId> - <version>${project.version}</version> - <type>zip</type> - <overWrite>false</overWrite> - </artifactItem> - </artifactItems> - <includes>**/*.class</includes> - <excludes>**/*.java</excludes> - <outputDirectory>${project.build.directory}</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>true</overWriteSnapshots> - </configuration> - </execution> - </executions> - </plugin> - <!-- Include the standard NOTICE and LICENSE --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-remote-resources-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>process</goal> - </goals> - <configuration> - <skip>false</skip> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Export-Package> - org.apache.logging.slf4j, - org.slf4j.impl - </Export-Package> - <Require-Capability> - osgi.extender;filter:="(osgi.extender=osgi.serviceloader.registrar)" - </Require-Capability> - <Provide-Capability> - osgi.serviceloader;osgi.serviceloader=org.slf4j.spi.SLF4JServiceProvider - </Provide-Capability> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - <reporting> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-changes-plugin</artifactId> - <version>${changes.plugin.version}</version> - <reportSets> - <reportSet> - <reports> - <report>changes-report</report> - </reports> - </reportSet> - </reportSets> - <configuration> - <issueLinkTemplate>%URL%/show_bug.cgi?id=%ISSUE%</issueLinkTemplate> - <useJql>true</useJql> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <version>${checkstyle.plugin.version}</version> - <configuration> - <!--<propertiesLocation>${vfs.parent.dir}/checkstyle.properties</propertiesLocation> --> - <configLocation>${log4jParentDir}/checkstyle.xml</configLocation> - <suppressionsLocation>${log4jParentDir}/checkstyle-suppressions.xml</suppressionsLocation> - <enableRulesSummary>false</enableRulesSummary> - <propertyExpansion>basedir=${basedir}</propertyExpansion> - <propertyExpansion>licensedir=${log4jParentDir}/checkstyle-header.txt</propertyExpansion> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>${javadoc.plugin.version}</version> - <configuration> - <bottom><![CDATA[<p align="center">Copyright © {inceptionYear}-{currentYear} {organizationName}. All Rights Reserved.<br /> - Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, - and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p>]]></bottom> - <!-- module link generation is completely broken in the javadoc plugin for a multi-module non-aggregating - project --> - <detectOfflineLinks>false</detectOfflineLinks> - <linksource>true</linksource> - </configuration> - <reportSets> - <reportSet> - <id>non-aggregate</id> - <reports> - <report>javadoc</report> - </reports> - </reportSet> - </reportSets> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>findbugs-maven-plugin</artifactId> - <version>${findbugs.plugin.version}</version> - <configuration> - <fork>true</fork> - <jvmArgs>-Duser.language=en</jvmArgs> - <threshold>Normal</threshold> - <effort>Default</effort> - <excludeFilterFile>${log4jParentDir}/findbugs-exclude-filter.xml</excludeFilterFile> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jxr-plugin</artifactId> - <version>${jxr.plugin.version}</version> - <reportSets> - <reportSet> - <id>non-aggregate</id> - <reports> - <report>jxr</report> - </reports> - </reportSet> - <reportSet> - <id>aggregate</id> - <reports> - <report>aggregate</report> - </reports> - </reportSet> - </reportSets> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-pmd-plugin</artifactId> - <version>${pmd.plugin.version}</version> - <configuration> - <targetJdk>${maven.compiler.target}</targetJdk> - </configuration> - </plugin> - </plugins> - </reporting> -</project> - http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java b/log4j-slf4j18/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java deleted file mode 100644 index 332d16d..0000000 --- a/log4j-slf4j18/src/main/java/org/apache/logging/slf4j/SLF4JServiceProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import org.slf4j.ILoggerFactory; -import org.slf4j.IMarkerFactory; -import org.slf4j.spi.MDCAdapter; - -public class SLF4JServiceProvider implements org.slf4j.spi.SLF4JServiceProvider { - - public static final String REQUESTED_API_VERSION = "1.8.99"; - - private ILoggerFactory loggerFactory; - private IMarkerFactory markerFactory; - private MDCAdapter mdcAdapter; - - @Override - public ILoggerFactory getLoggerFactory() { - return loggerFactory; - } - - @Override - public IMarkerFactory getMarkerFactory() { - return markerFactory; - } - - @Override - public MDCAdapter getMDCAdapter() { - return mdcAdapter; - } - - @Override - public String getRequesteApiVersion() { - return REQUESTED_API_VERSION; - } - - @Override - public void initialize() { - loggerFactory = new Log4jLoggerFactory(); - markerFactory = new Log4jMarkerFactory(); - mdcAdapter = new Log4jMDCAdapter(); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider b/log4j-slf4j18/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider deleted file mode 100644 index 1577f12..0000000 --- a/log4j-slf4j18/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider +++ /dev/null @@ -1 +0,0 @@ -org.apache.logging.slf4j.SLF4JServiceProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/site/markdown/index.md ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/site/markdown/index.md b/log4j-slf4j18/src/site/markdown/index.md deleted file mode 100644 index 6e3f3f6..0000000 --- a/log4j-slf4j18/src/site/markdown/index.md +++ /dev/null @@ -1,40 +0,0 @@ -<!-- vim: set syn=markdown : --> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. ---> - -# Log4j 2 SLF4J Binding - -The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use -Log4j 2 as the implementation. - -## Requirements - -The Log4j 2 SLF4J Binding has a dependency on the Log4j 2 API as well as the SLF4J API. -For more information, see [Runtime Dependencies](../runtime-dependencies.html). - -## Usage - -The SLF4J binding provided in this component cause all the SLF4J APIs to be routed to Log4j 2. Simply -include the Log4j 2 SLF4J Binding jar along with the Log4j 2 jars and SLF4J API jar to cause all SLF4J -logging to be handled by Log4j 2. - -<div class="alert alert-danger"> -Use of the Log4j 2 SLF4J Binding (log4j-slf4j-impl-2.0.jar) together with -the SLF4J adapter (log4j-to-slf4j-2.0.jar) should -never be attempted, as it will cause events to endlessly be routed between -SLF4J and Log4j 2. -</div> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/site/site.xml ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/site/site.xml b/log4j-slf4j18/src/site/site.xml deleted file mode 100644 index a1f9106..0000000 --- a/log4j-slf4j18/src/site/site.xml +++ /dev/null @@ -1,52 +0,0 @@ -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You 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. - ---> -<project name="SLF4J Binding Using Log4j" - xmlns="http://maven.apache.org/DECORATION/1.4.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> - <body> - <links> - <item name="Apache" href="http://www.apache.org/" /> - <item name="Logging Services" href="http://logging.apache.org/"/> - <item name="Log4j" href="../index.html"/> - </links> - - <!-- Component-specific reports --> - <menu ref="reports"/> - - <!-- Overall Project Info --> - <menu name="Log4j Project Information" img="icon-info-sign"> - <item name="Dependencies" href="../dependencies.html" /> - <item name="Dependency Convergence" href="../dependency-convergence.html" /> - <item name="Dependency Management" href="../dependency-management.html" /> - <item name="Project Team" href="../team-list.html" /> - <item name="Mailing Lists" href="../mail-lists.html" /> - <item name="Issue Tracking" href="../issue-tracking.html" /> - <item name="Project License" href="../license.html" /> - <item name="Source Repository" href="../source-repository.html" /> - <item name="Project Summary" href="../project-summary.html" /> - </menu> - - <menu name="Log4j Project Reports" img="icon-cog"> - <item name="Changes Report" href="../changes-report.html" /> - <item name="JIRA Report" href="../jira-report.html" /> - <item name="Surefire Report" href="../surefire-report.html" /> - <item name="RAT Report" href="../rat-report.html" /> - </menu> - </body> -</project> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java b/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java deleted file mode 100644 index 7efc0e5..0000000 --- a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CallerInformationTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.apache.logging.log4j.junit.LoggerContextRule; -import org.apache.logging.log4j.test.appender.ListAppender; -import org.junit.ClassRule; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CallerInformationTest { - - // config from log4j-core test-jar - private static final String CONFIG = "log4j2-calling-class.xml"; - - @ClassRule - public static final LoggerContextRule ctx = new LoggerContextRule(CONFIG); - - @Test - public void testClassLogger() throws Exception { - final ListAppender app = ctx.getListAppender("Class").clear(); - final Logger logger = LoggerFactory.getLogger("ClassLogger"); - logger.info("Ignored message contents."); - logger.warn("Verifying the caller class is still correct."); - logger.error("Hopefully nobody breaks me!"); - final List<String> messages = app.getMessages(); - assertEquals("Incorrect number of messages.", 3, messages.size()); - for (final String message : messages) { - assertEquals("Incorrect caller class name.", this.getClass().getName(), message); - } - } - - @Test - public void testMethodLogger() throws Exception { - final ListAppender app = ctx.getListAppender("Method").clear(); - final Logger logger = LoggerFactory.getLogger("MethodLogger"); - logger.info("More messages."); - logger.warn("CATASTROPHE INCOMING!"); - logger.error("ZOMBIES!!!"); - logger.warn("brains~~~"); - logger.info("Itchy. Tasty."); - final List<String> messages = app.getMessages(); - assertEquals("Incorrect number of messages.", 5, messages.size()); - for (final String message : messages) { - assertEquals("Incorrect caller method name.", "testMethodLogger", message); - } - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java b/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java deleted file mode 100644 index 0138cea..0000000 --- a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/CustomFlatMarker.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import java.util.Iterator; - -import org.slf4j.Marker; - -/** - * Test Marker that may contain no reference/parent Markers. - * @see <a href="https://issues.apache.org/jira/browse/LOG4J2-793">LOG4J2-793</a> - */ -public class CustomFlatMarker implements Marker { - private static final long serialVersionUID = -4115520883240247266L; - - private final String name; - - public CustomFlatMarker(final String name) { - this.name = name; - } - - @Override - public String getName() { - return name; - } - - @Override - public void add(final Marker reference) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean remove(final Marker reference) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean hasChildren() { - return hasReferences(); - } - - @Override - public boolean hasReferences() { - return false; - } - - @Override - public Iterator<Marker> iterator() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean contains(final Marker other) { - return false; - } - - @Override - public boolean contains(final String name) { - return false; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java b/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java deleted file mode 100644 index 59f69e0..0000000 --- a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j1222Test.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.Assert.*; - -/** - * Tests logging during shutdown. - */ -public class Log4j1222Test -{ - - @Test - public void homepageRendersSuccessfully() - { - System.setProperty("log4j.configurationFile", "log4j2-console.xml"); - Runtime.getRuntime().addShutdownHook(new ShutdownHook()); - } - - private static class ShutdownHook extends Thread { - - private static class Holder { - private static final Logger LOGGER = LoggerFactory.getLogger(Log4j1222Test.class); - } - - @Override - public void run() - { - super.run(); - trigger(); - } - - private void trigger() { - Holder.LOGGER.info("Attempt to trigger"); - assertTrue("Logger is of type " + Holder.LOGGER.getClass().getName(), Holder.LOGGER instanceof Log4jLogger); - - } - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java b/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java deleted file mode 100644 index 8934f29..0000000 --- a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4j2_1482_Slf4jTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import org.apache.logging.log4j.core.layout.Log4j2_1482_Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Tests https://issues.apache.org/jira/browse/LOG4J2-1482 - */ -public class Log4j2_1482_Slf4jTest extends Log4j2_1482_Test { - - @Override - protected void log(final int runNumber) { - if (runNumber == 2) { - // System.out.println("Set a breakpoint here."); - } - final Logger logger = LoggerFactory.getLogger("auditcsvfile"); - final int val1 = 9, val2 = 11, val3 = 12; - logger.info("Info Message!", val1, val2, val3); - logger.info("Info Message!", val1, val2, val3); - logger.info("Info Message!", val1, val2, val3); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/922fefdc/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java ---------------------------------------------------------------------- diff --git a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java b/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java deleted file mode 100644 index af7c394..0000000 --- a/log4j-slf4j18/src/test/java/org/apache/logging/slf4j/Log4jMarkerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.logging.slf4j; - -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.MarkerManager; -import org.junit.Assert; -import org.junit.Test; - -public class Log4jMarkerTest { - - @Test - public void testEquals() { - final Marker markerA = MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-A"); - final Marker markerB = MarkerManager.getMarker(Log4jMarkerTest.class.getName() + "-B"); - final Log4jMarker marker1 = new Log4jMarker(markerA); - final Log4jMarker marker2 = new Log4jMarker(markerA); - final Log4jMarker marker3 = new Log4jMarker(markerB); - Assert.assertEquals(marker1, marker2); - Assert.assertNotEquals(marker1, null); - Assert.assertNotEquals(null, marker1); - Assert.assertNotEquals(marker1, marker3); - } -}
