Java 日志组件,Apache Log4j 2.4.1 发布
jopen 9年前
Log4j 2 是Log4j的升级版,与之前的版本Log4j 1.x相比、有重大的改进,在修正了Logback固有的架构问题的同时,改进了许多Logback所具有的功能。
Log4j 2的特性以及改进有:
- API分离:Log4j将API与实现分离开来。开发人员现在可以很清楚地知道能够使用哪些没有兼容问题的类和方法,同时又允许通过自己实现来增强功能。
- 改进的性能:Log4j 2的性能在某些关键领域比Log4j 1.x更快,而且大多数情况下与Logback相当。更多的信息请参考性能。
- 多个API支持:Log4j 2提供最棒的性能的同时,还支持SLF4J和公共日志记录API。
- 自动配置加载:像Logback一样,一旦配置发生改变,Log4j 2可以自动载入这些更改后的配置信息,又与Logback不同,配置发生改变时不会丢失任何日志事件。
- 高级过滤功能:与Logback类似,Log4j 2可以支持基于上下文数据、标记,正则表达式以及日志事件中的其他组件的过滤。Log4j 2 能够专门指定适用于所有的事件,无论这些事件在传入Loggers之前还是正在传给 appenders。另外,过滤器还可以与Loggers关联起来。与Logback不同的是,Filter公共类可以用于任何情况。
- 插件架构:所有可以配置的组件都以Log4j插件的形式来定义。同样地,不需要修改任何Log4j代码就可以创建新的Appender、Layout、 Pattern Convert 等等。Log4j自动识别预定义的插件,如果在配置中引用到这些插件,Log4j就自动载入使用。
- 属性支持:属性可以在配置文件中引用,也可以直接替代或传入潜在的组件,属性在这些组件中能够动态解析。属性可以是配置文件,系统属性,环境变量,线程上下文映射以及事件中的数据中定义的值。用户可以通过增加自己的Lookup插件来定制自己的属性。
新特性: o LOG4J2-1129: Allow PatternLayout to select a pattern to use based on some selection criteria. o LOG4J2-1145: Add %equals to PatternLayout to test and replace patterns with strings. o LOG4J2-1147: Add %equalsIgnoreCase to PatternLayout to test and replace patterns with strings. o LOG4J2-1146: Add %notEmpty to PatternLayout to avoid output of patterns where all variables are empty. o LOG4J2-1020: Add possibility to set shutdown timeout on AsyncAppender. 修复Bugs: o LOG4J2-1153: Fixed NullPointerException when only root logger is defined (and no named loggers) in configuration properties file. o LOG4J2-1140: Fixed bug where headers were not being written to first file with RollingFileAppender. o LOG4J2-1149: Fixed bug where PatternLayout predefined date pattern with time zone always renders default date format. o LOG4J2-1050: Fixed Log4jLookup. o LOG4J2-1142: Fix potential memory leak in web applications by using a straight ThreadLocal field instead of subclassing ThreadLocal. o LOG4J2-1135: Compression on rollover was broken: log file was renamed to .zip but not compressed. o LOG4J2-1127: log4j2.xml cannot be parsed on Oracle Weblogic 12c. o LOG4J2-1132: Do not use MongoDB driver 2.13.3 deprecated methods. o LOG4J2-1144: Add %markerSimpleName in pattern layout should evaluate to marker name (not toString()). o LOG4J2-1126: Web site corrections and updates. 变化: o LOG4J2-1151: Performance improvement: backport Java 8 fast ISO-8859-1 String to byte[] encoder to AbstractStringLayout. o LOG4J2-935: Performance improvement when converting Strings to byte[] arrays. o LOG4J2-1040: Update MongoDB driver from 2.13.3 to 3.0.4. o LOG4J2-1128: Reuse StringBuilder to improve performance for String-based layouts: CSV, GELF, HTML, RFC524, Syslog. o LOG4J2-1131: Update mongo-java-driver from 2.13.2 to 2.13.3. o LOG4J2-1138: Do not use Jackson deprecated methods. o LOG4J2-1139: Update Jackson from 2.6.1 to 2.6.2. o LOG4J2-1150: Update kafka-clients from 0.8.2.1 to 0.8.2.2.更多改进内容请看发行说明。