tree: 5ba5a994151ecc7f714a57cb98c96c24a4bb4033 [path history] [tgz]
  1. .mvn/
  2. log4j-1.2-api/
  3. log4j-api/
  4. log4j-api-java9/
  5. log4j-bom/
  6. log4j-core/
  7. log4j-core-its/
  8. log4j-distribution/
  9. log4j-flume-ng/
  10. log4j-iostreams/
  11. log4j-jcl/
  12. log4j-jmx-gui/
  13. log4j-jul/
  14. log4j-liquibase/
  15. log4j-nosql/
  16. log4j-osgi/
  17. log4j-perf/
  18. log4j-samples/
  19. log4j-slf4j-impl/
  20. log4j-taglib/
  21. log4j-to-slf4j/
  22. log4j-web/
  23. src/
  24. .dockerignore
  25. .gitattributes
  26. .gitignore
  27. .travis-toolchains.xml
  28. .travis.yml
  29. BUILDING.md
  30. checkstyle-header.txt
  31. checkstyle-import-control.xml
  32. checkstyle-suppressions.xml
  33. checkstyle.xml
  34. CONTRIBUTING.md
  35. doap_log4j2.rdf
  36. Dockerfile
  37. findbugs-exclude-filter.xml
  38. jenkins-toolchains.xml
  39. LICENSE.txt
  40. mvnw
  41. mvnw.cmd
  42. NOTICE.txt
  43. pom.xml
  44. README.md
  45. RELEASE-NOTES.md
  46. toolchains-docker.xml
  47. toolchains-sample-linux.xml
  48. toolchains-sample-mac.xml
  49. toolchains-sample-win.xml
README.md

Apache Log4j 2

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.

![Jenkins Status](https://builds.apache.org/buildStatus/icon?job=Log4j 2.x) Travis Status Coverage Status

Usage

Maven users can add the following dependencies to their pom.xml file:

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.8</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8</version>
  </dependency>
</dependencies>

Gradle users can add the following to their build.gradle file:

dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8'
  compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8'
}

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>

Documentation

The Log4j 2 User's Guide is available here or as a downloadable PDF.

Requirements

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.

License

Apache Log4j 2 is distributed under the Apache License, version 2.0.

Download

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.

Issue Tracking

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.

Building From Source

Log4j requires Apache Maven 3.x. To build from source and install to your local Maven repository, execute the following:

mvn install

Contributing

We love contributions! Take a look at our contributing page.