Log4j – Apache Log4j 2 - Apache Log4j 2 http://logging.apache.org/log4j/2.x/

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.

Features

API Separation

The API for Log4j is separate from the implementation making it clear for application developers which classes and methods they can use while ensuring forward compatibility. This allows the Log4j team to improve the implementation safely and in a compatible manner.

Improved Performance

Log4j 2 contains next-generation Asynchronous Loggers based on the LMAX Disruptor library. In multi-threaded scenarios Asynchronous Loggers have 18 times higher throughput and orders of magnitude lower latency than Log4j 1.x and Logback. See Asynchronous Logging Performance for details. Otherwise, Log4j 2 significantly outperforms Log4j 1.x, Logback and java.util.logging, especially in multi-threaded applications. See Performance for more information.

Support for multiple APIs

While the Log4j 2 API will provide the best performance, Log4j 2 provides support for the Log4j 1.2, SLF4J, Commons Logging and java.util.logging (JUL) APIs.

Avoid lock-in

Applications coded to the Log4j 2 API always have the option to use any SLF4J-compliant library as their logger implementation with the log4j-to-slf4j adapter.

Automatic Reloading of Configurations

Like Logback, Log4j 2 can automatically reload its configuration upon modification. Unlike Logback, it will do so without losing log events while reconfiguration is taking place.

Advanced Filtering

Like Logback, Log4j 2 supports filtering based on context data, markers, regular expressions, and other components in the Log event. Filtering can be specified to apply to all events before being passed to Loggers or as they pass through Appenders. In addition, filters can also be associated with Loggers. Unlike Logback, you can use a common Filter class in any of these circumstances.

Plugin Architecture

Log4j uses the plugin pattern to configure components. As such, you do not need to write code to create and configure an Appender, Layout, Pattern Converter, and so on. Log4j automatically recognizes plugins and uses them when a configuration references them.

Property Support

You can reference properties in a configuration, Log4j will directly replace them, or Log4j will pass them to an underlying component that will dynamically resolve them. Properties come from values defined in the configuration file, system properties, environment variables, the ThreadContext Map, and data present in the event. Users can further customize the property providers by adding their own Lookup Plugin.

Java 8 Lambda Support

Previously, if a log message was expensive to construct, you would often explicitly check if the requested log level is enabled before constructing the message. Client code running on Java 8 can benefit from Log4j’s lambda support. Since Log4j will not evaluate a lambda expression if the requested log level is not enabled, the same effect can be achieved with less code.

Custom Log Levels

In Log4j 2, custom log levels can easily be defined in code or in configuration. No subclassing is required.

Garbage-free

During steady state logging, Log4j 2 is garbage-free in stand-alone applications, and low garbage in web applications. This reduces pressure on the garbage collector and can give better response time performance.

Integrating with Application Servers

Version 2.10.0 introduces a the module log4j-appserver to improve integration with Apache Tomcat and Eclipse Jetty.

Documentation

The Log4j 2 User’s Guide is available on this site 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.

News

Log4j 2.11.1 is now available for production. The API for Log4j 2 is not compatible with Log4j 1.x, however an adapter is available to allow applications to continue to use the Log4j 1.x API. Adapters are also available for Apache Commons Logging, SLF4J, and java.util.logging.

Log4j 2.11.1 is the latest release of Log4j and contains several bug fixes that were found after the release of Log4j 2.6. The list of fixes can be found in the latest changes report.

Note that subsequent to the release of Log4j 2.6 a minor source incompatibility with prior release was found due to the addition of new methods to the Logger interface. If you have code that does:

  1. logger.error(null, "This is the log message", throwable);

or similar with any log level you will get a compiler error saying the reference is ambiguous. To correct this either do:

  1. logger.error("This is the log message", throwable);

or

  1. logger.error((Marker) null, "This is the log message", throwable);

Log4j 2.11.1 maintains binary compatibility with previous releases.

Log4j 2的更多相关文章

  1. 利用log4j+mongodb实现分布式系统中日志统一管理

    背景     在分布式系统当中,我们有各种各样的WebService,这些服务可能分别部署在不同的服务器上,并且有各自的日志输出.为了方便对这些日志进行统一管理和分析.我们可以将日志统一输出到指定的数 ...

  2. org.apache.log4j.Logger详解

    org.apache.log4j.Logger 详解 1. 概述 1.1. 背景 在应用程序中添加日志记录总的来说基于三个目的 :监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工 ...

  3. (转)配置Log4j(很详细)

    来自:http://blog.csdn.net/yttcjj/article/details/37957317 Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存 ...

  4. Log4j记录日志步骤

    记录日志对调试Bug很有帮助  亲身体会 个人习惯用Log4J,大家可以在apache网站:jakarta.apache.org/log4j 可以免费下载到Log4j最新版本的软件包. Log4j支持 ...

  5. log4j:ERROR Failed to rename [/log/xxx.log] to [/log/xxx.log.2016-11-23.log]

    Log4j报错: log4j:ERROR Failed to rename [/log/xxx.log] to [/log/xxx.log.2016-11-23.log] google了一下发现是个b ...

  6. 项目自动化建构工具gradle 入门2——log4j输出helloWorld

    上一章节呢,有一个能跑的程序了.但是对做工程的人来说,用日志输出感觉比用System.out要有档次一点.比如使用log4j.直接上例子: 1进入D:\work\gradle\log目录  ,您电脑没 ...

  7. java日志组件介绍(common-logging,log4j,slf4j,logback )

    转自:http://www.blogjava.net/daiyongzhi/archive/2014/04/13/412364.html common-logging是apache提供的一个通用的日志 ...

  8. Log4j配置详解(转)

    一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...

  9. log4j+mybatis打印数据库日志

    参考文献:一:http://blog.csdn.net/rangqiwei/article/details/50825090 二:http://www.mybatis.org/mybatis-3/zh ...

  10. log4j分离日志输出 自定义过滤 自定义日志文件

    普通的log4j.properties 定义: ### set log levels ### log4j.rootLogger = debug,D,E ## Disable other log log ...

随机推荐

  1. github 搜索技巧

    1.关键词 + 指定开发语言 bitcoin language:javascript 2.关键词 + stars 数量 + forks 数量 bitcoin stars:> forks:>

  2. Atitit.antlr实现词法分析

    Atitit.antlr实现词法分析 1.1.  antlrworks-1.4.3.jar   wizard1 1.2. 词法的类型 id,int,float ,comment,str,char,wh ...

  3. std::thread “terminate called without an active exception”

    最近在使用std::thread的时候,遇到这样一个问题: std::thread t(func); 如果不使用调用t.join()就会遇到 "terminate called whitho ...

  4. python-hanoi

    #!/usr/bin/env python #-*- coding:utf-8 -*- ############################ #File Name: hanoi.py #Autho ...

  5. Mac上搭建直播服务器Nginx

    Mac上搭建直播服务器Nginx 1.安装Homebrew,执行命令 Homebrew简称brew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件,可以说Homebrew就 ...

  6. maven依赖workspace和jar包

    当开发maven项目时,如果workspace中有maven依赖的项目,并且groupid和artifactId都相同,maven就会优先依赖workspace中的项目文件,如果想依赖maven库中的 ...

  7. JVM Specification 9th Edition (2) Chapter 1. Introduction

    Chapter 1. Introduction 翻译太累了,我就这样的看英文吧. 内容列表 1.1. A Bit of History 1.2. The Java Virtual Machine 1. ...

  8. IT 服务管理工具 iTop

    iTop,作为全面支持ITIL流程的一款ITSM工具,具有强大的ITSM功能,开源免费.简单易用. iTop,即IT运营门户(IT Operation Portal),是一个开源web应用程序,用于I ...

  9. Pyspider学习

    简介 国人编写的强大的网络爬虫系统并自带强大的WebUI,采用Python语言编写吗,分布式架构.支持多种数据库后端 pyspider中文网站:http://www.pyspider.cn/ 源码网址 ...

  10. 消息队列ipc的一些设置

    Linux IPC 参数设定- 命令方式: echo 80 > /proc/sys/vm/overcommit_ratio, etc MSGMNB 每个消息队列的最大字节限制. MSGMNI 整 ...