Skip to content
Commits on Source (2)
# Apache Log4j 2.10.0 Release Notes
The Apache Log4j 2 team is pleased to announce the Log4j 2.10.0 release!
<!---
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.
-->
# Apache Log4j 2.11.1 Release Notes
The Apache Log4j 2 team is pleased to announce the Log4j 2.11.1 release!
Apache Log4j is a well known framework for logging application behavior. Log4j 2 is an upgrade
to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides
......@@ -9,10 +25,11 @@ property substitution using Lookups, multiple patterns on a PatternLayout and as
Loggers. Another notable Log4j 2 feature is the ability to be "garbage-free" (avoid allocating
temporary objects) while logging. In addition, Log4j 2 will not lose events while reconfiguring.
This release contains new features, bugfixes and minor enhancements. Some of the new features include support
for the Java 9 module system, support for the new SLF4j 1.8 binding mechanism, simplification of the Log4j
property naming scheme, and native support of Jetty's logger. Log4j API is now a fully compliant module
while the other Log4j jars are named automatic modules.
This release contains new features, bugfixes and minor enhancements.
Due to a break in compatibility in the SLF4J binding, Log4j now ships with two versions of the SLF4J to Log4j adapters.
log4j-slf4j-impl should be used with SLF4J 1.7.x and earlier and log4j-slf4j18-impl should be used with SLF4J 1.8.x and
later.
As of Log4j 2.9.0, the Log4j API was modified to use java.util.ServiceLoader to locate Log4j implementations,
although the former binding mechanism is still supported. The Log4j API jar is now a multi-release jar
......@@ -47,112 +64,126 @@ We do, however, discourage the use of SerializedLayout and recommend JsonLayout
</Socket>
</Appenders>
Note that the XML, JSON and YAML formats changed in the 2.11.0 release: they no longer have the "timeMillis" attribute and instead have an "Instant" element with "epochSecond" and "nanoOfSecond" attributes.
Note that subsequent to the 2.9.0 release, for security reasons, Log4j does not process DTD in XML files.
If you used DTD for including snippets, you have to use XInclude or Composite Configuration instead.
The Log4j 2.10.0 API, as well as many core components, maintains binary compatibility with previous releases.
The Log4j 2.11.1 API, as well as many core components, maintains binary compatibility with previous releases.
## GA Release 2.10.0
## GA Release 2.11.1
Changes in this version include:
### New Features
* [LOG4J2-2120](https://issues.apache.org/jira/browse/LOG4J2-2120):
Properly escape newlines and other control characters in JSON. Thanks to Carter Douglas Kozak.
* [LOG4J2-2109](https://issues.apache.org/jira/browse/LOG4J2-2109):
Add property to disable message pattern converter lookups. Thanks to Carter Douglas Kozak.
* [LOG4J2-2112](https://issues.apache.org/jira/browse/LOG4J2-2112):
MapMessage should use deep toString for values. Thanks to Carter Douglas Kozak.
* [LOG4J2-2103](https://issues.apache.org/jira/browse/LOG4J2-2103):
XML encoding for PatternLayout.
* [LOG4J2-2114](https://issues.apache.org/jira/browse/LOG4J2-2114):
Provide a native Log4j 2 implementation of Eclipse Jetty's org.eclipse.jetty.util.log.Logger.
* [LOG4J2-1203](https://issues.apache.org/jira/browse/LOG4J2-1203):
Allow filtering of line breaks in layout pattern. Thanks to Robert Turner.
* [LOG4J2-2098](https://issues.apache.org/jira/browse/LOG4J2-2098):
Add a noop AppenderSkeleton for applications still using Log4j 1.x.
* [LOG4J2-2062](https://issues.apache.org/jira/browse/LOG4J2-2062):
Add possibility of sending the key of a message to Kafka using KafkaAppender. Thanks to Jorge Sanchez.
* [LOG4J2-2056](https://issues.apache.org/jira/browse/LOG4J2-2056):
Modularize Log4j-api and make most other log4j jars automatic modules.
* [LOG4J2-1431](https://issues.apache.org/jira/browse/LOG4J2-1431):
Simplify log4j system property naming scheme.
* [LOG4J2-1809](https://issues.apache.org/jira/browse/LOG4J2-1809):
Add global configuration environment SPI.
* [LOG4J2-1694](https://issues.apache.org/jira/browse/LOG4J2-1694):
Add fields with fixed values to JSON/XML/YAML layouts. Thanks to Michal Dvořák.
* [LOG4J2-2054](https://issues.apache.org/jira/browse/LOG4J2-2054):
Provide ways to configure SSL that avoid plain-text passwords in the log4j configuration. The configuration may
now specify a system environment variable that holds the password, or the path to a file that holds the password.
* [LOG4J2-2071](https://issues.apache.org/jira/browse/LOG4J2-2071):
Add org.apache.logging.log4j.core.config.composite.CompositeConfiguration#toString(). Thanks to Carter Kozak.
### Fixed Bugs
* [LOG4J2-2107](https://issues.apache.org/jira/browse/LOG4J2-2107):
MapMessage supports both StringBuilderFormattable and MultiformatMessage. Thanks to Carter Douglas Kozak.
* [LOG4J2-2102](https://issues.apache.org/jira/browse/LOG4J2-2102):
MapMessage JSON encoding will escape keys and values. Thanks to Carter Douglas Kozak.
* [LOG4J2-2101](https://issues.apache.org/jira/browse/LOG4J2-2101):
Non-string value in MapMessage caused ClassCastException. Thanks to Carter Douglas Kozak.
* [LOG4J2-2091](https://issues.apache.org/jira/browse/LOG4J2-2091):
Log4j respects the configured "log4j2.is.webapp" property Thanks to Carter Douglas Kozak.
* [LOG4J2-2100](https://issues.apache.org/jira/browse/LOG4J2-2100):
LevelMixIn class for Jackson is coded incorrectly
* [LOG4J2-2087](https://issues.apache.org/jira/browse/LOG4J2-2087):
Jansi now needs to be enabled explicitly (by setting system property `log4j.skipJansi` to `false`). To avoid causing problems for web applications, Log4j will no longer automatically try to load Jansi without explicit configuration. Thanks to Andy Gumbrecht.
* [LOG4J2-2060](https://issues.apache.org/jira/browse/LOG4J2-2060):
AbstractDatabaseManager should make a copy of LogEvents before holding references to them: AsyncLogger log events are mutable.
* [LOG4J2-2055](https://issues.apache.org/jira/browse/LOG4J2-2055):
If Log4j is used as the Tomcat logging implementation startup might fail if an application also uses Log4j.
* [LOG4J2-2031](https://issues.apache.org/jira/browse/LOG4J2-2031):
Until this change, messages appeared out of order in log file any time when the async logging queue was full.
With this change, messages are only logged out of order to prevent deadlock when Log4j2 detects recursive
logging while the queue is full.
* [LOG4J2-2053](https://issues.apache.org/jira/browse/LOG4J2-2053):
Exception java.nio.charset.UnsupportedCharsetException: cp65001 in 2.9.0.
* [LOG4J2-1216](https://issues.apache.org/jira/browse/LOG4J2-1216):
Nested pattern layout options broken. Thanks to Thies Wellpott, Barna Zsombor Klara, GFriedrich.
* [LOG4J2-2070](https://issues.apache.org/jira/browse/LOG4J2-2070):
Log4j1XmlLayout does not provide the entire stack trace, it is missing the caused by information. Thanks to Doug Hughes.
* [LOG4J2-2036](https://issues.apache.org/jira/browse/LOG4J2-2036):
CompositeConfiguration supports Reconfiguration. PR #115. Thanks to Robert Haycock.
* [LOG4J2-2073](https://issues.apache.org/jira/browse/LOG4J2-2073):
Log4j-config.xsd should make AppenderRef optional for each Logger element. Thanks to Patrick Lucas.
* [LOG4J2-2074](https://issues.apache.org/jira/browse/LOG4J2-2074):
The console appender should say why it cannot load JAnsi.
* [LOG4J2-2085](https://issues.apache.org/jira/browse/LOG4J2-2085):
Wrong Apache Commons CSV version referenced in the Javadoc of CsvParameterLayout. Thanks to István Neuwirth.
* [LOG4J2-2389](https://issues.apache.org/jira/browse/LOG4J2-2389):
ThrowableProxy was saving and retrieving cache entries using different keys. Thanks to Liu Wen.
* [LOG4J2-2316](https://issues.apache.org/jira/browse/LOG4J2-2316):
If root LoggerConfig does not have a Level return ERROR.
* [LOG4J2-2390](https://issues.apache.org/jira/browse/LOG4J2-2390):
Fix broken links in log4j web documentation. Thanks to anton-balaniuc.
* [LOG4J2-2343](https://issues.apache.org/jira/browse/LOG4J2-2343):
The OSGi Activator specified an incorrect version. Thanks to Raymond Augé.
* [LOG4J2-2305](https://issues.apache.org/jira/browse/LOG4J2-2305):
Make java.util.ServiceLoader properly work in OSGi by using the Service Loader Mediator Specification. Thanks to Björn Kautler.
* [LOG4J2-2305](https://issues.apache.org/jira/browse/LOG4J2-2305):
Split the SLF4J binding into 2 implementations - one for SLF4J 1.7.x and one for SLF4J 1.8+.
* [LOG4J2-2268](https://issues.apache.org/jira/browse/LOG4J2-2268):
Improve plugin error message when elements are missing. Thanks to Tilman Hausherr.
* [LOG4J2-2283](https://issues.apache.org/jira/browse/LOG4J2-2283):
ParserConfigurationException when using Log4j with oracle.xml.jaxp.JXDocumentBuilderFactory. Thanks to Vishnu Priya Matha.
* [LOG4J2-2300](https://issues.apache.org/jira/browse/LOG4J2-2300):
PoolingDriverConnectionSource does not take into account properties, user name, and password.
* [LOG4J2-2307](https://issues.apache.org/jira/browse/LOG4J2-2307):
MutableLogEvent and RingBufferLogEvent message mementos retain the original format string.
* [LOG4J2-2032](https://issues.apache.org/jira/browse/LOG4J2-2032):
Curly braces in parameters are not treated as placeholders. Thanks to Kostiantyn Shchepanovskyi.
* [LOG4J2-2317](https://issues.apache.org/jira/browse/LOG4J2-2317):
MutableLogEvent.getNonNullImmutableMessage and Log4jLogEvent.makeMessageImmutable retain format and parameters.
* [LOG4J2-2318](https://issues.apache.org/jira/browse/LOG4J2-2318):
Messages are no longer mutated when the asynchronous queue is full. A warning is logged to the status logger instead.
* [LOG4J2-2320](https://issues.apache.org/jira/browse/LOG4J2-2320):
Fix NPE in AbstractLogger when another exception is thrown, masking the root cause.
* [LOG4J2-2321](https://issues.apache.org/jira/browse/LOG4J2-2321):
AsyncLogger uses the correct level when unspecified. This provides parity between AsyncLogger and Logger.
* [LOG4J2-2322](https://issues.apache.org/jira/browse/LOG4J2-2322):
Custom ContextSelector implementations which select an AsyncLoggerContext disable LoggerConfig.includeLocation
by default for parity with AsyncLoggerContextSelector.
* [LOG4J2-2269](https://issues.apache.org/jira/browse/LOG4J2-2269):
MutableLogEvent references to other objects are cleared after each use.
Fix a memory leak causing references to parameters to be held after synchronous logging with thread locals enabled.
* [LOG4J2-2301](https://issues.apache.org/jira/browse/LOG4J2-2301):
Mixed async loggers no longer forget parameter values, providing some appenders with an array of nulls.
* [LOG4J2-2331](https://issues.apache.org/jira/browse/LOG4J2-2331):
RollingFileManager debug logging avoids string concatenation and errant braces in favor of parameterized logging. Thanks to Mike Baranski.
* [LOG4J2-2333](https://issues.apache.org/jira/browse/LOG4J2-2333):
Handle errors thrown in default disruptor ExceptionHandler implementations to avoid killing background threads.
* [LOG4J2-2334](https://issues.apache.org/jira/browse/LOG4J2-2334):
Add API org.apache.logging.log4j.core.appender.AsyncAppender.getQueueSize().
* [LOG4J2-2336](https://issues.apache.org/jira/browse/LOG4J2-2336):
Remove duplicate hyphen from the AsyncLoggerConfig background thread name.
* [LOG4J2-2347](https://issues.apache.org/jira/browse/LOG4J2-2347):
Update Apache Commons Compress from 1.16.1 to 1.17.
* [LOG4J2-2352](https://issues.apache.org/jira/browse/LOG4J2-2352):
RingBufferLogEvent memento messages provide the expected format string, and no longer attempt to substitute parameters into curly braces in parameter toString values.
Both RingBufferLogEvent and MutableLogEvent memento implementations memoize results to avoid rebuilding formatted string values.
* [LOG4J2-2355](https://issues.apache.org/jira/browse/LOG4J2-2355):
PropertiesUtil ignores non-string system properties. Fixes a NoClassDefFoundError initializing StatusLogger
caused by an NPE while initializing the static PropertiesUtil field. Thanks to Henrik Brautaset Aronsen.
* [LOG4J2-2362](https://issues.apache.org/jira/browse/LOG4J2-2362):
Fixed a memory leak in which ReusableObjectMessage would hold a reference to the most recently logged object.
* [LOG4J2-2312](https://issues.apache.org/jira/browse/LOG4J2-2312):
Jackson layouts used with AsyncLoggerContextSelector output the expected format rather than only a JSON string of the message text.
* [LOG4J2-2364](https://issues.apache.org/jira/browse/LOG4J2-2364):
Fixed a memory leak in which ReusableParameterizedMessage would hold a reference to the most recently
logged throwable and provided varargs array.
* [LOG4J2-2368](https://issues.apache.org/jira/browse/LOG4J2-2368):
Nested logging doesn't clobber AbstractStringLayout cached StringBuidlers
* [LOG4J2-2373](https://issues.apache.org/jira/browse/LOG4J2-2373):
StringBuilders.escapeJson implementation runs in linear time. Escaping large JSON strings
in EncodingPatternConverter and MapMessage will perform significantly better. Thanks to Kevin Meurer.
* [LOG4J2-2376](https://issues.apache.org/jira/browse/LOG4J2-2376):
StringBuilders.escapeXml implementation runs in linear time. Escaping large XML strings
in EncodingPatternConverter and MapMessage will perform significantly better. Thanks to Kevin Meurer.
* [LOG4J2-2377](https://issues.apache.org/jira/browse/LOG4J2-2377):
NullPointerException in org.apache.logging.log4j.util.LoaderUtil.getClassLoaders() when using Bootstrap class loader. Thanks to Mirko Rzehak, Gary Gregory.
* [LOG4J2-2382](https://issues.apache.org/jira/browse/LOG4J2-2382):
Update Mongodb 3 driver from 3.6.3 to 3.8.0.
* [LOG4J2-2388](https://issues.apache.org/jira/browse/LOG4J2-2388):
Thread indefinitely blocked when logging a message in an interrupted thread. Thanks to Failled.
### Changes
* [LOG4J2-2076](https://issues.apache.org/jira/browse/LOG4J2-2076):
Split up log4j-nosql into one module per appender.
* [LOG4J2-2088](https://issues.apache.org/jira/browse/LOG4J2-2088):
Upgrade picocli to 2.0.3 from 0.9.8.
* [LOG4J2-2025](https://issues.apache.org/jira/browse/LOG4J2-2025):
Provide support for overriding the Tomcat Log class in Tomcat 8.5+.
* [LOG4J2-2057](https://issues.apache.org/jira/browse/LOG4J2-2057):
Support new SLF4J binding mechanism introduced in SLF4J 1.8.
* [LOG4J2-2052](https://issues.apache.org/jira/browse/LOG4J2-2052):
Disable thread name caching by default when running on Java 8u102 or later.
* [LOG4J2-1896](https://issues.apache.org/jira/browse/LOG4J2-1896):
Update classes in org.apache.logging.log4j.core.net.ssl in APIs from String to a PasswordProvider producing
char[] for passwords.
* [LOG4J2-2078](https://issues.apache.org/jira/browse/LOG4J2-2078):
Update LMAX disruptor from 3.3.6 to 3.3.7.
* [LOG4J2-2081](https://issues.apache.org/jira/browse/LOG4J2-2081):
Update Apache Commons Compress from 1.14 to 1.15.
* [LOG4J2-2089](https://issues.apache.org/jira/browse/LOG4J2-2089):
[TagLib] Update servlet-api provided dependency from 2.5 to 3.0.1.
* [LOG4J2-2096](https://issues.apache.org/jira/browse/LOG4J2-2096):
Update Apache Kafka kafka-clients from 0.11.0.1 to 1.0.0.
* [LOG4J2-2077](https://issues.apache.org/jira/browse/LOG4J2-2077):
Update from Jackson 2.9.1 to 2.9.2.
* [LOG4J2-2117](https://issues.apache.org/jira/browse/LOG4J2-2117):
Jackson dependencies for 2.9.2 incorrectly bring in jackson-annotations 2.9.0 instead of 2.9.2.
* [LOG4J2-1721](https://issues.apache.org/jira/browse/LOG4J2-1721):
Allow composite configuration for context parameter. Thanks to Phokham Nonava.
* [LOG4J2-2302](https://issues.apache.org/jira/browse/LOG4J2-2302):
Status logger should show the Log4j name and version when initializing itself.
* [LOG4J2-2304](https://issues.apache.org/jira/browse/LOG4J2-2304):
Log4j2 2.8.2 JMX unregister NullPointerException. Thanks to wumengsheng.
* [LOG4J2-2311](https://issues.apache.org/jira/browse/LOG4J2-2311):
Update Jackson from 2.9.4 to 2.9.5.
* [LOG4J2-2313](https://issues.apache.org/jira/browse/LOG4J2-2313):
Update LMAX Disruptor from 3.3.7 to 3.4.2.
* [LOG4J2-548](https://issues.apache.org/jira/browse/LOG4J2-548):
Log4j 2.0 ERROR "Could not search jar" with JBoss EAP 6.2. Thanks to Shehata, Paresh Varke, Eric Victorson, Martin Laforet.
* [LOG4J2-2328](https://issues.apache.org/jira/browse/LOG4J2-2328):
Update JAnsi from 1.17 to 1.17.1.
* [LOG4J2-2351](https://issues.apache.org/jira/browse/LOG4J2-2351):
Added AbstractLogEvent.getMutableInstant to allow the MutableInstant instance to be modified by classes extending AbstractLogEvent.
* [LOG4J2-2357](https://issues.apache.org/jira/browse/LOG4J2-2357):
Update Jackson from 2.9.5 to 2.9.6.
* [LOG4J2-2358](https://issues.apache.org/jira/browse/LOG4J2-2358):
Update Kafka client from 1.0.0 to 1.1.0.
* [LOG4J2-2384](https://issues.apache.org/jira/browse/LOG4J2-2384):
Update Kafka client from 1.1.0 to 1.1.1.
* [LOG4J2-2385](https://issues.apache.org/jira/browse/LOG4J2-2385):
Update Groovy from 2.4.13 to 2.5.1.
* [LOG4J2-2386](https://issues.apache.org/jira/browse/LOG4J2-2386):
Update optional Apache Commons DBCP from 2.2.0 to 2.4.0.
---
Apache Log4j 2.10.0 requires a minimum of Java 7 to build and run. Log4j 2.3 was the
Apache Log4j 2.11.1 requires a minimum of Java 7 to build and run. Log4j 2.3 was the
last release that supported Java 6.
Basic compatibility with Log4j 1.x is provided through the log4j-1.2-api component, however it
......
......@@ -34,7 +34,7 @@
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/home/jenkins/tools/java/latest1.7</jdkHome>
<jdkHome>/home/jenkins/tools/java/latest1.8</jdkHome>
</configuration>
</toolchain>
<toolchain>
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.10.0</version>
<version>2.11.1</version>
<relativePath>../</relativePath>
</parent>
<artifactId>log4j-1.2-api</artifactId>
......
......@@ -51,9 +51,11 @@ public abstract class AppenderSkeleton implements Appender, OptionHandler {
super();
}
@Override
public void activateOptions() {
}
@Override
public void addFilter(Filter newFilter) {
if(headFilter == null) {
headFilter = tailFilter = newFilter;
......@@ -65,17 +67,21 @@ public abstract class AppenderSkeleton implements Appender, OptionHandler {
protected abstract void append(LoggingEvent event);
@Override
public void clearFilters() {
headFilter = tailFilter = null;
}
@Override
public void finalize() {
}
@Override
public ErrorHandler getErrorHandler() {
return this.errorHandler;
}
@Override
public Filter getFilter() {
return headFilter;
}
......@@ -84,10 +90,12 @@ public abstract class AppenderSkeleton implements Appender, OptionHandler {
return headFilter;
}
@Override
public Layout getLayout() {
return layout;
}
@Override
public final String getName() {
return this.name;
}
......@@ -104,6 +112,7 @@ public abstract class AppenderSkeleton implements Appender, OptionHandler {
* This method is never going to be called in Log4j 2 so there isn't much point in having any code in it.
* @param event The LoggingEvent.
*/
@Override
public void doAppend(LoggingEvent event) {
}
......@@ -112,16 +121,19 @@ public abstract class AppenderSkeleton implements Appender, OptionHandler {
*
* @since 0.9.0
*/
@Override
public synchronized void setErrorHandler(ErrorHandler eh) {
if (eh != null) {
this.errorHandler = eh;
}
}
@Override
public void setLayout(Layout layout) {
this.layout = layout;
}
@Override
public void setName(String name) {
this.name = name;
}
......
......@@ -39,6 +39,7 @@ public class LogWithMDCTest {
public void testMDC() throws Exception {
MDC.put("Key1", "John");
MDC.put("Key2", "Smith");
try {
final Logger logger = Logger.getLogger("org.apache.test.logging");
logger.debug("This is a test");
final ListAppender listApp = (ListAppender) CTX.getAppender("List");
......@@ -48,5 +49,9 @@ public class LogWithMDCTest {
assertTrue(msgs.size() == 1);
assertTrue("Key1 is missing", msgs.get(0).contains("Key1=John"));
assertTrue("Key2 is missing", msgs.get(0).contains("Key2=Smith"));
} finally {
MDC.remove("Key1");
MDC.remove("Key2");
}
}
}
......@@ -40,6 +40,7 @@ public class LogWithRouteTest {
public void testMDC() throws Exception {
MDC.put("Type", "Service");
MDC.put("Name", "John Smith");
try {
final Logger logger = Logger.getLogger("org.apache.test.logging");
logger.debug("This is a test");
final ListAppender listApp = (ListAppender) CTX.getAppender("List");
......@@ -49,5 +50,9 @@ public class LogWithRouteTest {
assertTrue(msgs.size() == 1);
assertTrue("Type is missing", msgs.get(0).contains("Type=Service"));
assertTrue("Name is missing", msgs.get(0).contains("Name=John Smith"));
} finally {
MDC.remove("Type");
MDC.remove("Name");
}
}
}
......@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
......@@ -167,10 +168,15 @@ public class Log4j1ConfigurationFactoryTest {
try {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
appender.stop(10, TimeUnit.SECONDS);
System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
assertEquals(tempFileName, appender.getFileName());
} finally {
try {
Files.deleteIfExists(tempFilePath);
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
......
......@@ -16,18 +16,22 @@
*/
package org.apache.log4j.layout;
import static org.junit.Assert.assertEquals;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.impl.ContextDataFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.junit.ThreadContextRule;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.util.StringMap;
import org.junit.Rule;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class Log4j1XmlLayoutTest {
@Rule
public ThreadContextRule threadContextRule = new ThreadContextRule();
@Test
public void testWithoutThrown() {
final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(false, true);
......@@ -53,9 +57,9 @@ public class Log4j1XmlLayoutTest {
public void testWithPropertiesAndLocationInfo() {
final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(true, true);
final Map<String, String> contextMap = new HashMap<>(2);
contextMap.put("key1", "value1");
contextMap.put("key2", "value2");
final StringMap contextMap = ContextDataFactory.createContextData(2);
contextMap.putValue("key1", "value1");
contextMap.putValue("key2", "value2");
final Log4jLogEvent event = Log4jLogEvent.newBuilder()
.setLoggerName("a.B")
.setLevel(Level.INFO)
......@@ -63,7 +67,7 @@ public class Log4j1XmlLayoutTest {
.setTimeMillis(System.currentTimeMillis() + 17)
.setIncludeLocation(true)
.setSource(new StackTraceElement("pack.MyClass", "myMethod", "MyClass.java", 17))
.setContextMap(contextMap)
.setContextData(contextMap)
.build();
final String result = layout.toSerializable(event);
......
......@@ -16,58 +16,57 @@
*/
package org.apache.log4j.pattern;
import static org.junit.Assert.assertEquals;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.impl.ContextDataFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.util.StringMap;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class Log4j1MdcPatternConverterTest {
@Test
public void testConverter0() {
final Map<String, String> contextMap = new HashMap<>(0);
final StringMap contextMap = ContextDataFactory.createContextData(0);
final String expected = "{}";
test(contextMap, expected, null);
}
@Test
public void testConverter1() {
final Map<String, String> contextMap = new HashMap<>(1);
contextMap.put("key1", "value1");
final StringMap contextMap = ContextDataFactory.createContextData(1);
contextMap.putValue("key1", "value1");
final String expected = "{{key1,value1}}";
test(contextMap, expected, null);
}
@Test
public void testConverter2() {
final Map<String, String> contextMap = new HashMap<>(2);
contextMap.put("key1", "value1");
contextMap.put("key2", "value2");
final StringMap contextMap = ContextDataFactory.createContextData(2);
contextMap.putValue("key1", "value1");
contextMap.putValue("key2", "value2");
final String expected = "{{key1,value1}{key2,value2}}";
test(contextMap, expected, null);
}
@Test
public void testConverterWithKey() {
final Map<String, String> contextMap = new HashMap<>(2);
contextMap.put("key1", "value1");
contextMap.put("key2", "value2");
final StringMap contextMap = ContextDataFactory.createContextData(2);
contextMap.putValue("key1", "value1");
contextMap.putValue("key2", "value2");
final String expected = "value1";
test(contextMap, expected, new String[] {"key1"});
}
private void test(final Map<String, String> contextMap, final String expected, final String[] options) {
private void test(final StringMap contextMap, final String expected, final String[] options) {
final LogEvent event = Log4jLogEvent.newBuilder()
.setLoggerName("MyLogger")
.setLevel(Level.DEBUG)
.setMessage(new SimpleMessage("Hello"))
.setContextMap(contextMap)
.setContextData(contextMap)
.build();
final StringBuilder sb = new StringBuilder();
final Log4j1MdcPatternConverter converter = Log4j1MdcPatternConverter.newInstance(options);
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.10.0</version>
<version>2.11.1</version>
<relativePath>../</relativePath>
</parent>
<artifactId>log4j-api-java9</artifactId>
......@@ -60,7 +60,7 @@
<configuration>
<toolchains>
<jdk>
<version>9</version>
<version>[9, )</version>
</jdk>
</toolchains>
</configuration>
......@@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>${deploy.plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
......
......@@ -32,17 +32,12 @@
<include>**/*.class</include>
</includes>
<excludes>
<exclude>module-info.class</exclude>
<exclude>**/Dummy.class</exclude>
<exclude>**/spi/Provider.class</exclude>
<exclude>**/util/PropertySource.class</exclude>
<exclude>**/message/ThreadDumpMessage.class</exclude>
<exclude>**/message/ThreadDumpMessage$ThreadInfoFactory.class</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/classes</outputDirectory>
<includes>
<include>module-info.class</include>
</includes>
</fileSet>
</fileSets>
</assembly>
......@@ -21,5 +21,8 @@ module org.apache.logging.log4j {
exports org.apache.logging.log4j.spi;
exports org.apache.logging.log4j.status;
exports org.apache.logging.log4j.util;
uses org.apache.logging.log4j.spi.Provider;
uses org.apache.logging.log4j.util.PropertySource;
uses org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory;
}
/*
* 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.log4j.util;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class PropertySource {
}
/*
* 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.log4j.message;
/**
* This is a dummy class and is only here to allow module-info.java to compile. It will not
* be copied into the log4j-api module.
*/
public class ThreadDumpMessage {
public static interface ThreadInfoFactory {
}
}
/*
* 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.log4j.util.internal;
import java.io.ObjectInputFilter;
import java.util.Arrays;
import java.util.List;
public class DefaultObjectInputFilter implements ObjectInputFilter {
private static final List<String> REQUIRED_JAVA_CLASSES = Arrays.asList(
"java.math.BigDecimal",
"java.math.BigInteger",
// for Message delegate
"java.rmi.MarshalledObject",
"[B"
);
private static final List<String> REQUIRED_JAVA_PACKAGES = Arrays.asList(
"java.lang.",
"java.time",
"java.util.",
"org.apache.logging.log4j.",
"[Lorg.apache.logging.log4j."
);
private final ObjectInputFilter delegate;
public DefaultObjectInputFilter() {
delegate = null;
}
public DefaultObjectInputFilter(ObjectInputFilter filter) {
delegate = filter;
}
/**
* This is easier to use via reflection.
* @param filter The ObjectInputFilter.
* @return The DefaultObjectInputFilter.
*/
public static DefaultObjectInputFilter newInstance(ObjectInputFilter filter) {
return new DefaultObjectInputFilter(filter);
}
@Override
public Status checkInput(FilterInfo filterInfo) {
Status status = null;
if (delegate != null) {
status = delegate.checkInput(filterInfo);
if (status != Status.UNDECIDED) {
return status;
}
}
ObjectInputFilter serialFilter = ObjectInputFilter.Config.getSerialFilter();
if (serialFilter != null) {
status = serialFilter.checkInput(filterInfo);
if (status != Status.UNDECIDED) {
// The process-wide filter overrides this filter
return status;
}
}
if (filterInfo.serialClass() != null) {
String name = filterInfo.serialClass().getName();
if (isAllowedByDefault(name) || isRequiredPackage(name)) {
return Status.ALLOWED;
}
}
return Status.REJECTED;
}
private static boolean isAllowedByDefault(final String name) {
return isRequiredPackage(name) || REQUIRED_JAVA_CLASSES.contains(name);
}
private static boolean isRequiredPackage(final String name) {
for (final String packageName : REQUIRED_JAVA_PACKAGES) {
if (name.startsWith(packageName)) {
return true;
}
}
return false;
}
}
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId>
<version>2.10.0</version>
<version>2.11.1</version>
<relativePath>../</relativePath>
</parent>
<artifactId>log4j-api</artifactId>
......@@ -88,7 +88,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<executions>
<execution>
<id>unpack-classes</id>
......@@ -159,7 +159,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<executions>
<execution>
<id>default-jar</id>
<goals>
<goal>jar</goal>
</goals>
<configuration combine.self="override">
<archive>
<manifestFile>${manifestfile}</manifestFile>
<manifestEntries>
......@@ -176,11 +182,28 @@
</manifestEntries>
</archive>
</configuration>
<executions>
</execution>
<execution>
<id>default</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<archive>
<manifestFile>${manifestfile}</manifestFile>
<manifestEntries>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Specification-Vendor>${project.organization.name}</Specification-Vendor>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
......@@ -213,13 +236,14 @@
*
</Import-Package>
<Bundle-Activator>org.apache.logging.log4j.util.Activator</Bundle-Activator>
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>${deploy.plugin.version}</version>
</plugin>
</plugins>
</build>
......
......@@ -211,6 +211,7 @@ public final class ThreadContext {
* <em>Consider private, used for testing.</em>
*/
static void init() {
ThreadContextMapFactory.init();
contextMap = null;
final PropertiesUtil managerProps = PropertiesUtil.getProperties();
disableAll = managerProps.getBooleanProperty(DISABLE_ALL);
......@@ -225,6 +226,8 @@ public final class ThreadContext {
}
if (contextMap instanceof ReadOnlyThreadContextMap) {
readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap;
} else {
readOnlyContextMap = null;
}
}
......
/*
* 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.log4j.message;
/**
* {@link Clearable} objects may be reset to a reusable state.
*
* This type should be combined into {@link ReusableMessage} as a default method for 3.0.
*
* @since 2.11.1
*/
interface Clearable {
/**
* Resets the object to a clean state.
*/
void clear();
}
......@@ -109,7 +109,7 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Constructs a new instance based on an existing Map.
* Constructs a new instance based on an existing {@link Map}.
* @param map The Map.
*/
public MapMessage(final Map<String, V> map) {
......@@ -485,7 +485,10 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
public Throwable getThrowable() {
return null;
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final boolean value) {
......@@ -493,6 +496,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final byte value) {
......@@ -500,6 +505,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final char value) {
......@@ -507,6 +514,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final double value) {
......@@ -514,6 +523,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final float value) {
......@@ -521,6 +532,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final int value) {
......@@ -528,6 +541,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final long value) {
......@@ -535,6 +550,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final Object value) {
......@@ -542,6 +559,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final short value) {
......@@ -549,6 +568,8 @@ public class MapMessage<M extends MapMessage<M, V>, V> implements MultiFormatStr
}
/**
* Default implementation does nothing.
*
* @since 2.9
*/
protected void validate(final String key, final String value) {
......
/*
* 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.log4j.message;
/**
* An operation that accepts two input arguments and returns no result.
*
* <p>
* The third parameter lets callers pass in a stateful object to be modified with the key-value pairs,
* so the ParameterConsumer implementation itself can be stateless and potentially reusable.
* </p>
*
* @param <S> state data
* @see ReusableMessage
* @since 2.11
*/
public interface ParameterConsumer<S> {
/**
* Performs an operation given the specified arguments.
*
* @param parameter the parameter
* @param parameterIndex Index of the parameter
* @param state
*/
void accept(Object parameter, int parameterIndex, S state);
}