今年一直关注log4j 2,但至今还没有出正式版。等不及了,今天正式向大家介绍一下log4j的升级框架,log4j 2。

log4j,相信大家都熟悉,至今对java影响最大的logging系统,至今仍有很多系统在使用log4j,但毕竟这个版本出的太早,Java都从1.2到7.0了,log4j怎么总是在1.2的版本呢?

不得承认,写log4j的那个人确实很牛,之后又写了slf4j和logback作为log4j 1.x的替代品。但是,最终,原作者可能发现,还是log4j的江山大,所以,最终决定重写log4j,因此诞生了log4j 2。哈哈,以上都是个人杜撰。

综合比较log4j和slf4及logback组合,log4j 2具有更好的性能,特别是在多线程的程序中,以及logback和slf4j的种种优点,因为作者已经非常熟悉logging系统,因此,log4j 2注定将成为又一个著名的日志组件。

下面简单介绍一下,log4j 2的一些新特性。原文在这里。

为什么要Log4j 2?(原作者自己所写,本人做了简单翻译)

Log4j 1.x has been widely adopted and used in many applications. However, through the years development on it has slowed down. It has become more difficult to maintain due to its need to be compliant with very old versions of Java. Its alternative, SLF4J/Logback made many needed improvements to the framework. So why bother with Log4j 2? Here are a few of the reasons.

Log4j1.x已经被广泛应用到各个系统及框架中。然后,1.x毕竟太古老,代码很久没有更新。目前,Log4j 1.x的代码已经很难维护,因为它依赖于很多Jdk老版本的api。作为Log4j 1.x的替代品,SLF4J/Logback已经对日志系统做了很大的改进,那么,为什么我们还需要Log4j 2?

1、Log4j 2 is designed to be usable as an audit logging framework. Both Log4j 1.x and Logback will lose events while reconfiguring. Log4j 2 will not. in Logback exceptions in Appenders are never visible to the application. In Log4j 2 Appenders can be configured to allow the exception to percolate to the application

Log4j 2被设计成对安全审计有用的日志框架。在Logback框架中,当输出日志产生异常时,从来不会告诉被调用方,而log4j 2,这个将是可配置的。

2、  Log4j 2 contains next-generation lock-free Asynchronous Loggers based on the LMAX Disruptor library. In multi-threaded scenarios Asynchronous Loggers have 10 times higher throughput and orders of magnitude lower latency than Log4j 1.x and Logback.

Log4j 2使用了新一代的基于LMAX Disruptor的无锁异步日志系统。在多线程的程序中,异步日志系统吞吐量比Log4j 1.x和logback高10倍,而时间延迟更低(这个比较吸引人)

3、Log4j 2 uses a Plugin system that makes it extremely easy to extend the framework by adding new Appenders, Filters, Layouts, Lookups, and Pattern Converters without requiring any changes to Log4j.

Log4j 2使用插件机制,更灵活。扩展appenders,Filters,Layouts,Lookups和Pattern Converters将变得更加简单,而不用去更改任何Log4j本身。

4、Due to the Plugin system configuration is simpler. Entries in the configuration do not require a class name to be specified.

因为插件机制,在配置文件中,不再需要指定定制的类名称。

(下面这些个人感觉是一些在logback上面的小改进,我就不翻译了)

5、Support for Message objects. Messages allow support for interesting and complex constructs to be passed through the logging system and be efficiently manipulated. Users are free to create their own Message types and write custom Layouts, Filters and Lookups to manipulate them.

6、Log4j 1.x supports Filters on Appenders. Logback added TurboFilters to allow filtering of events before they are processed by a Logger. Log4j 2 supports Filters that can be configured to process events before they are handled by a Logger, as they are processed by a Logger or on an Appender.

7、Many Logback Appenders do not accept a Layout and will only send data in a fixed format. Most Log4j 2 Appenders accept a Layout, allowing the data to be transported in any format desired.

8、  Layouts in Log4j 1.x and Logback return a String. This resulted in the problems discussed at Logback Encoders. Log4j 2 takes the simpler approach that Layouts always return a byte array. This has the advantage that it means they can be used in virtually any Appender, not just the ones that write to an OutputStream.

9、The Syslog Appender supports both TCP and UDP as well as support for the BSD syslog and the RFC 5424 formats.

10、Log4j 2 takes advantage of Java 5 concurrency support and performs locking at the lowest level possible. Log4j 1.x has known deadlock issues. Many of these are fixed in Logback but many Logback classes still require synchronization at a fairly high level.

Log4j 2在底层尽可能使用了Java5提供的对并发及锁支持的工具类。Lo4j 1.x有死锁的bug。Logback中修复了log4j 1.x的很多bug,但是,logback中的有很多类采用同步机制(这种机制导致性能下降)。

11、It is an Apache Software Foundation project following the community and support model used by all ASF projects. If you want to contribute or gain the right to commit changes just follow the path outlined at Contributing

另外,作者针对性能做了专门介绍:

One of the often-cited arguments against logging is its computational cost. This is a legitimate concern as even moderately sized applications can generate thousands of log requests. Much effort was spent measuring and tweaking logging performance. Log4j claims to be fast and flexible: speed first, flexibility second.

决定日志系统好坏的一个重要参数就是它的性能指标。这很重要,因为即使一个中等规模的应用程序每秒产生的日志都数以千计。我们花费了大量精力在测量和调整log4j 2的性能。log4j声称,日志框架应该很快,并且要求灵活:速度第一,灵活性第二。

对这类话题感兴趣?欢迎发送邮件至donlianli@

关于我:邯郸人,擅长Java,Javascript,Extjs,oracle sql。

更多我之前的文章,可以访问 我的空间

java log4j和logback,跨过slf4j和logback,直接晋级log4j 2相关推荐

  1. java log4j logback jcl_知识总结-Java日志框架Log4j、Log4j2、logback、slf4j、简介

    功能简介 上一篇介绍了为什么打印日志.什么时候打印日志以及怎么打印日志.本篇介绍下在项目开发中常见的日志组件以及关系. 先看一张图 接口:将所有日志实现适配到了一起,用统一的接口调用. 实现:目前主流 ...

  2. 【Java从0到架构师】日志处理 - SLF4J、Logback、Log4j 2.x

    日志处理 - SLF4J.Logback.Log4j 2.x SLF4J + Log4j 1.x SLF4J + Logback Logback - 配置文件 Logback - 控制台彩色打印 Lo ...

  3. java日志,需要知道的几件事(commons-logging,log4j,slf4j,logback)

    java日志,需要知道的几件事 如果对于commons-loging .log4j .slf4j .LogBack 等都已经非常清楚了,可以忽略本文.几次解决日志冲突问题时对这几个概念的简单总结,希望 ...

  4. Java各类日志门面(slf4j,commons-logging)和日志框架(log4j,logback)联系和区别

    日志门面 1.Apache通用日志接口(commons-logging.jar) Apache Commons包中的一个,包含了日志功能,必须使用的jar包.这个包本身包含了一个Simple Logg ...

  5. 一文读懂常用日志框架(Log4j、SLF4J、Logback)有啥区别

    1.概述 相信目前大多数情况下,不管是开源框架或是平时我们工作编码中都离不开一种框架,它就是日志框架.因此本节就简单了解一下我们常用日志框架的区别. 2.Commons Logging common- ...

  6. java日志之slf4j与logback简单使用

    最近在开发遇到日志是使用slf4j与logback.xml的配置,所以就记录下来了. 1.导入这几个jar包: Logback 分为三个模块:logback-core,logback-classic, ...

  7. SLF4J 之logback.xml配置文件实例及其说明

    为什么80%的码农都做不了架构师?>>>    对于java后端程序员来说,如何记录日志是一个小话题,只要在网上随便找一个log4j的简单说明,就可以用了.但是,要真正了解日志记录的 ...

  8. How to setup SLF4J and LOGBack in a web app - fast--转载

    原文:https://wiki.base22.com/display/btg/How+to+setup+SLF4J+and+LOGBack+in+a+web+app+-+fast Logback is ...

  9. 结合使用slf4j和Logback教程

    在当前文章中,我将向您展示如何配置您的应用程序以使用slf4j和logback作为记录器解决方案. Java简单日志记录外观(slf4j)是各种日志记录框架的简单外观,例如JDK日志记录(java.u ...

最新文章

  1. 2020上半年收集到的优质AI文章 – 自然语言处理
  2. 在pcduino上实现图像识别的程序
  3. oracle 用户创建角色,oracle普通用户创建和加权限
  4. Centos部署YApi
  5. 家庭组计算机无法,【求助】Windows无法从该家庭组中删除你的计算机
  6. 每日一学:如何用matplotlib展示图片
  7. linux查看某进程的连接,linux下查看指定进程的所有连接信息(转)
  8. 不忘初心,恪守信条:微盟经历的从删库到跑路的数据灾难
  9. HDU2112 HDU Today 最短路+字符串哈希
  10. 放肆的使用UIBezierPath和CAShapeLayer画各种图形
  11. regexp(正则表达式)的使用
  12. html5 抓取网页数据,从网页抓取数据的一般方法
  13. 人工智能表格票据识别-要素信息自动识别提取
  14. 手绘风海报怎么做?手绘素材在哪里找?
  15. Notion Avatar Maker - 一个简单有趣的 Notion 风格头像生成器,可生成百万个免费商用的头像
  16. 【FPGA】Verilog编程实现SDRAM读写(一) ----- 初识SDRAM
  17. 嵌入式编程与PC编程有何区别
  18. 幸运抽奖java技术文档_原生js轮盘抽奖实例分析(幸运大转盘抽奖)
  19. 剑指offe-机器人的运动范围
  20. 【图形】输出一行星号

热门文章

  1. 泊松回归、gamma回归、Tweedie回归等广义线性回归模型GLM的评估指标:校准曲线、 洛伦兹曲线、卡方检验、AIC、BIC、偏差(Deviance)指标
  2. 集成学习模型(xgboost、lightgbm、catboost)进行回归预测构建实战:异常数据处理、缺失值处理、数据重采样resample、独热编码、预测特征检查、特征可视化、预测结构可视化、模型
  3. pandas读取多个excel文件并拼接(append)起来形成最终的dataframe、与标签文件连接(join)形成最终学习数据集
  4. 特征重要度(feature importance)如何获取、排序、可视化、以及可视化阈值设置?
  5. gif加文字 php,gif动态图片添加文字 gif制作软件 怎样给gif动态图片添加文字
  6. ML基石_10_LogisticRegression
  7. tf.keras.layers.Conv1D 一维卷积 示例
  8. python 类的特殊属性、特殊方法 __str__,__bases__,__mor__,__add__,__call__
  9. ImportError: cannot import name ‘secure_filename‘的解决办法
  10. OSError: Unable to download 'ffmpeg.win32.exe'. Perhaps there is a no internet connection? If there