This article is for reprint study
English Original:apache.org, compilation: Importnew-Tengkai
Connection: http://www.importnew.com/3046.html
About log4j 2
Log4j 2 is an upgraded version of log4j, with significant improvements compared to the previous version log4j 1.x, which improves the functionality of many logback while correcting the inherent architectural problems of logback.
The features and improvements of log4j 2 are:
API separation: log4j separates the API from the implementation. Developers now have a clear idea of what classes and methods are available that do not have compatibility issues, while allowing for enhanced functionality through their own implementations.
Improved performance: The performance of log4j 2 is faster than log4j 1.x in some key areas, and in most cases is equivalent to Logback. For more information, refer to performance.
Multiple API support: The LOG4J 2 provides the best performance while supporting the SLF4J and public logging APIs.
Automatic configuration loading: Like Logback, once the configuration has changed, log4j 2 can automatically load these changed configuration information, and unlike Logback, no log events are lost when the configuration changes.
Advanced filtering features: Similar to Logback, log4j 2 can support filtering based on context data, tags, regular expressions, and other components in the log event. Log4j 2 can be specifically specified for all events, whether or not these events are passed to the loggers or are being passed to appenders. In addition, filters can be associated with loggers. Unlike Logback, the filter public class can be used in any situation.
Plug-in Architecture: all components that can be configured are defined in the form of a log4j plugin. Similarly, you can create new Appender, Layout, Pattern Convert, and so on without having to modify any log4j code. Log4j automatically identifies pre-defined plug-ins, and if they are referenced in the configuration, log4j is automatically loaded into use.
Property Support: Properties can be referenced in the configuration file, or they can be directly substituted or passed in to potential components, which can be parsed dynamically in these components. Properties can be configuration files, System properties, environment variables, thread context mappings, and values defined in the data in the event. Users can customize their properties by adding their own lookup plugins.
Document
log4j 2 user documentation can be read online here, or downloaded into PDF format.
Requirements
Log4j 2 requires at least Java 5 to be installed, but using Java 6 enhancements can improve performance. Some features require some optional dependencies, which are described in the documentation for the relevant features.
Information
Log4j 2 is now ready to be tested. The API is not compatible with the log4j 1.x, but the Log4j 1.x API can continue to be used through the adapter. Adapters are also available for Commons logging and slf4j.
Document
log4j 2 user documentation can be read online here, or downloaded into PDF format.
Requirements
Log4j 2 requires at least Java 5 to be installed, but using Java 6 enhancements can improve performance. Some features require some optional dependencies, which are described in the documentation for the relevant features.
Information
Log4j 2 is now ready to be tested. The API is not compatible with the log4j 1.x, but the Log4j 1.x API can continue to be used through the adapter. Adapters are also available for Commons logging and slf4j.
LOG4J 2.x Construction and installation
Build
Log 4j runs in the code warehouse under the Apache Software Foundation. The LOG4J code repository can find details on how to get the most current source code. You can download the latest source code according to log4j download instructions
Log4j 2.x uses Maven 2 or 3 as the build tool. You can generate log4j by running only "mvn install" in the root directory.
How to use the program
Before you use log4j in your program, you must ensure that the API and core jars are in the classpath of your program. Use MAVEN to add the following dependencies to Pom.xml.
<dependencies><dependency><groupid>org.apache.logging.log4j</groupid><artifactid >log4j-api</artifactId><version>2.0-beta3</version></dependency><dependency> <groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId>< Version>2.0-beta3</version></dependency></dependecies>
Apache Public log records
Public logging is used in many components, and different builds can choose the implementation of specific logging. In order to integrate the log functionality of these components into LOG4J 2, the following dependencies need to be added, and the Commons Logging jar cannot be removed
<dependencies><dependency><groupId>org.apache.logging.log4j.adapters</groupId>< artifactid>log4j-jcl</artifactid><version>2.0-beta3</version></dependency></ Dependecies>
Slf4j
SLF4J is another popular logging API that can be bound to log4j 2 by adding the following dependencies and slf4j dependencies.
<dependencies><dependency><groupId>org.apache.logging.log4j.adapters</groupId>< Artifactid>log4j-slf4j-impl</artifactid><version>2.0-beta3</version></dependency> </dependecies>
Upgrade considerations
Apache log4j 2 does not support compatibility with older versions. If you want to upgrade to log4j 2, keep the following in mind:
Requires Java 5
Simplifies the XML configuration and is incompatible with LOGJ4 1.x.
Property file configuration is not supported
Support for JSON configuration
Although log4j 2 cannot be directly compatible with the LOG4J 1.x, it is possible to reduce code changes from the upgrade by bringing a compatible bridge.
Log4j 2 Introduction