commit | a1c3c7829e2fe3edea415a25121e31fb0afc0f1a | [log] [tgz] |
---|---|---|
author | Matt Sicker <boards@gmail.com> | Sun Oct 06 13:25:49 2019 -0500 |
committer | Matt Sicker <boards@gmail.com> | Sun Oct 06 13:28:47 2019 -0500 |
tree | 74650d62751297b2f668b90189eb58f015d8db6d | |
parent | 15c59b3a6c3a8fca0104d835277b8fe327c911c6 [diff] |
Extract binder, injector, and name provider APIs This refactors some of the strategies used for configuring and instantiating plugins. The previously named ConfigurationInjectionBuilder classes have been renamed to be ConfigurationInjector as they are no longer builder classes. This API has been simplified to find an appropriate injector given an AnnotatedElement which can automatically set both the AnnotatedElement and the Annotation. Conversion types have been weakened to use java.lang.reflect.Type rather than Class. This introduces a new plugin SPI named OptionBinder for abstracting the binding strategies previously used in the massive PluginBuilder class as desired by LOG4J2-860. This SPI is extended to include support for method-based configuration injection into plugin builder classes as specified in LOG4J2-2700. This introduces another plugin SPI for specifying the name of an annotated element rather than relying on Java reflection to calculate the name. This SPI also fixes LOG4J2-2693. Signed-off-by: Matt Sicker <boards@gmail.com>
Apache Log4j 2 is an upgrade to Log4j that provides significant improvements over its predecessor, Log4j 1.x, and provides many of the improvements available in Logback while fixing some inherent problems in Logback's architecture.
By sending a pull request you grant the Apache Software Foundation sufficient rights to use and release the submitted work under the Apache license. You grant the same rights (copyright license, patent license, etc.) to the Apache Software Foundation as if you have signed a Contributor License Agreement. For contributions that are judged to be non-trivial, you will be asked to actually signing a Contributor License Agreement.
Users should refer to Maven, Ivy, Gradle, and SBT Artifacts on the Log4j web site for instructions on how to include Log4j into their project using their chosen build tool.
Basic usage of the Logger
API:
package com.example; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; public class Example { private static final Logger LOGGER = LogManager.getLogger(); public static void main(String... args) { String thing = args.length > 0 ? args[0] : "world"; LOGGER.info("Hello, {}!", thing); LOGGER.debug("Got calculated value only if debug enabled: {}", () -> doSomeCalculation()); } private static Object doSomeCalculation() { // do some complicated calculation } }
And an example log4j2.xml
configuration file:
<?xml version="1.0" encoding="UTF-8"?> <Configuration> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Logger name="com.example" level="INFO"/> <Root level="error"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration>
The Log4j 2 User's Guide is available here or as a downloadable PDF.
Log4j 2.4 and greater requires Java 7, versions 2.0-alpha1 to 2.3 required Java 6. Some features require optional dependencies; the documentation for these features specifies the dependencies.
Apache Log4j 2 is distributed under the Apache License, version 2.0.
How to download Log4j, and how to use it from Maven, Ivy and Gradle. You can access the latest development snapshot by using the Maven repository https://repository.apache.org/snapshots
, see Snapshot builds.
Issues, bugs, and feature requests should be submitted to the JIRA issue tracking system for this project.
Pull request on GitHub are welcome, but please open a ticket in the JIRA issue tracker first, and mention the JIRA issue in the Pull Request.
Log4j requires Apache Maven 3.x. To build from source and install to your local Maven repository, execute the following:
mvn install
We love contributions! Take a look at our contributing page.