intro to Apache Log4j 2

【0】README

0.1)本文作为 原文(http://logging.apache.org/log4j/2.x/)的译文,仅作参考, 旨在了解 Log4j 2 的相关知识
0.2) Apache Log4j 2 是Log4j的升级版,并对其前任Log4j 1.x 提供了很多改进和对 LogBack架构中的固有问题进行了修复。
0.3) 文末转载了原文(http://logging.apache.org/log4j/2.x/);


【1】一些Log4j 2 的特点和改进方面如下:

1.1)API分离:

  • Log4j 的API 从 实现中分离出来,并使得应用程序员对于使用什么样的类和方法更加清晰,但他们确定要保证先前兼容性的话。该改进允许Log4j 团队以兼容方式安全地改善其实现。

1.2)提高性能:

  • Log4j 2 包括了下一代基于LMAX分裂库的异步日志记录器。在多线程环境中, 相比于Log4j1.x ,异步日志记录器有高于其18倍的吞吐量和更低数量级的延迟。Logback 详情参见: https://logging.apache.org/log4j/2.x/manual/async.html#Performance 。其他的,在一些关键领域上,Log4j 2比 Log4j 1.x 执行地更快速,且Log4j 2 与大多数情况下的 Logback 架构有相似的地方,详情参见:https://logging.apache.org/log4j/2.x/performance.html 。

1.3)支持多种API:

  • 鉴于 Log4j 2 API提供了最佳性能,Log4j 2 也提供了对 SLF4J 和 通用Loging API 的支持;

1.4)自动重载配置信息:

  • 如 Logback 架构, 只要有更新,Log4j 2 能够自动重载其配置信息。与Logback 不同的是, Log4j 2这样做并没有遗漏日志事件;

1.5)高级过滤功能:

  • 如Logback架构,Log4j 2支持基于上下文数据、标记,正则表达式和其它日志事件中组件的过滤。在所有的事件被传递给日志记录器前或者当他们通过目的地传输类(Appender)时,可以对它们进行过滤。此外,过滤器还可以和日志记录器关联起来。和Logback 不同的是,你可以在任何情况下使用一个常见的过滤器。

1.6)插件架构:

  • Log4j 使用插件模式配置组件。同样地,你也不需要写代码来创建和配置目的地传输类(Appender),布局类(Layout),模式转换器类(Pattern Converter) 等等。Log4j 自动识别和使用组件,当有配置信息引用它们的时候。

1.7)属性支持:

  • 你可以引用配置信息里的属性,Log4j 将直接替换它们, 或者Log4j 将它们传递给底层组件,这些组件将动态地处理它们。属性值来源于定义在配置文件,系统属性,环境变量,线程上下文映射(ThreadContect Map)以及日志事件中数据的值。用户可以增加他们自己的 Lookup(http://logging.apache.org/log4j/2.x/manual/lookups.html) 插件来进一步自定义属性提供器;

1.8)Java 8 Lambda(λ) 支持:

  • 在以前,如果构造一条日志消息成本很高的话,那么在构建该日志消息前,你经常会很明确地检查是否该请求日志级别可用(enabled)。运行在 Java 8 上面的客户端代码可得益于Log4j 的 Lambda 支持。因为Log4j 不会去评估一个lambda(λ)表达式,如果该请求日志级别不可用的话, 即是说,更少的代码产生了相同的结果;

1.9)定制的日志级别:

  • 在Log4j 2中, 定制的日志级别很容易地在代码和配置信息中定义。不需要进行子类化。

1.10)文档:

  • Log4j 2的用户只能在本网址(http://logging.apache.org/log4j/2.x/manual/index.html)可以获得,也可以查看可下载的PDF文件(http://logging.apache.org/log4j/2.x/log4j-users-guide.pdf)

1.11)要求

  • Log4j 2.4 以及以上版本需要 Java 7 ,或者 java 6 2.0-alpha 1 到2.3。一些功能特点需要可选依赖性, 而文档指定了Log4j 2 功能特点所需要的依赖性;

1.12)新闻:

  • Log4j 2 现在可以用于生产。Log4j 2 的API和 Log4j 1.x 不兼容, 但 适配器允许应用继续使用 Log4j 1.x 的API 。适配器对于Apache 常见的日志记录类(Apache Commons Logging) 和 SLF4J 还是可用的。

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.

Some of the features and improvements in Log4j 2 are:

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 performs faster than Log4j 1.x in critical areas and similarly to Logback under most circumstances. 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 SLF4J and Commons Logging APIs.

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.

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 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 and SLF4J.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/331773.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php注册页面模板,选项卡式WordPress登陆注册模板

上次说到不用插件也可以修改WordPress登陆注册界面,不过只是简单的修改了CSS,缺少很多元素,例如header、导航、footer等,为了增加这些元素,我们可以采取另一种方式,将WordPress登陆注册界面做成page模板&am…

内核堆栈 用户堆栈_弹性堆栈介绍

内核堆栈 用户堆栈当您运行对公司至关重要的软件时,您将无法拥有仅用于分析一段时间前发生的事情的日志,让客户端告诉您您的应用程序已损坏,而您甚至不知道发生了什么是真实的问题。 解决该问题的方法之一是使用监视和日志记录。 大多数应用…

php 字符串 中文,php 中文字符串截取乱码

PHP截取字符串如果是英文直接用substr就可以了,但对于中文字符,用substring可能会导致乱码,那么将如何解决呢?1、通过函数mb_substr实现说明:mb_substr($str, $start, $length, $encoding);通过该函数即可,但需要加载p…

java 调试技巧

【0】README 0.1) 本文描述源代码均 转自 core java volume 1, 旨在理解 java 调试技巧 的相关知识; 【1】调试技巧相关 1.1)可以用下面的方法打印或记录任意变量的值: System.out.println("x " x); 或 …

jdk 版本和内部版本对应_JDK 14 Rampdown:内部版本27

jdk 版本和内部版本对应马克 雷因霍尔德( Mark Reinhold)最近的帖子“ JDK 14现在处于Rampdown第一阶段 ”宣布“我们现在处于Rampdown第一阶段”,并且“整体功能已冻结”。 JDK 14 Early Access Build #27(2019/12/12…

对一个java源文件进行正确编译,给定如下一个Java源文件Child.java,编译并运行Child.java,以下结果正确的是()...

总成化无本优部问决企题业内法解,给定流配特别题是物送问。而他再告真的不是己这却一诉自,个源文译并运行下某人重病的家得了假如人忽然间,的应对策略有他使用到。结果感是个人自我指一效能对:。哲学的规揭示律一般,管…

异常java.lang.Thread.dumpStack(Unknown Source)

转自: http://www.blogjava.net/landon/archive/2011/02/27/345265.html 昨天在公司写了一段代码,很简单,就是测试Thread的dumpStack方法的使用。 因为Thread的dumpStack方法不是很常用,但它对于如果想看看谁在运行时调用方法还是…

java集合框架——接口图+类图+遗留类图

【0】README 0.1)绝对的干货,理清 java集合框架中类和接口的层次关系;

构建maven项目插件_如何构建一个Maven插件

构建maven项目插件使用Okta的身份管理平台轻松部署您的应用程序 使用Okta的API在几分钟之内即可对任何应用程序中的用户进行身份验证,管理和保护。 今天尝试Okta。 由于其插件生态系统的普及,Apache Maven仍然是Java领域最受欢迎的构建工具。 很容易找到…

shu函数php,【函数分享】每日PHP函数分享(2021-3-3)

array_intersect_assoc — 带索引检查计算数组的交集说明array_intersect_assoc ( array $array1 , array $array2 , array $... ? ) : arrayarray_intersect_assoc() 返回一个数组,该数组包含了所有在 array1 中也同时出现在所有其它参数数组中的值。注意和 arra…

spring 注释_Spring@主要注释

spring 注释介绍: 当存在多个相同类型的bean时,使用Spring Primary批注为标记的bean提供更高的优先级。 默认情况下,Spring按类型自动连线。 因此,当Spring尝试自动装配并且有多个相同类型的bean时,我们将得到一个NoU…

java集合——集合接口+迭代器接口

【0】README 0.1) 本文描述转自 core java volume 1, 源代码 diy 的, 旨在理解 java集合框架——集合接口迭代器接口 的相关知识; 0.2) for full source code , please visit https://github.com/pacosonTang/core-j…

snmp在php中的使用,在php中转换python代码以计算snmpvlan掩码的最佳方法

我有一些python代码,我想在一个100%的php代码中使用。你知道我怎么转换代码吗???我在转换代码时遇到问题,尤其是部分get bit和set bit。在位掩码通过snmp从交换机中读取,掩码表示交换机端口位于定义的vlan中…

java ssl发送邮件_通过SSL发送的Java邮件

java ssl发送邮件抽象 本博客的目的是演示如何使用Java Mail通过具有SSL连接的SMTP服务器发送电子邮件。 免责声明 这篇文章仅供参考。 在使用所提供的任何信息之前,请认真思考。 从中学到东西,但最终自己做出决定,风险自负。 要求 我使用以…

java集合—— 链表(java中的所有链表都是双向链表)

【0】README 0.1) 本文描述转自 core java volume 1, 源代码 diy 的, 旨在理解 java集合—— 链表(java中的所有链表都是双向链表) 的相关知识; 0.2) for full source code , please visit ht…

使用matlab内存不足,Matlab内存不足问题(Out of memory)

今天遇到过这个错误:??? Error using > horzcatOut of memory. Type HELP MEMORY for your options.做算法仿真时,矩阵太大,超出内存了。当信号矩阵缩到可以满足内存时,仿真也没意义了,只有找解决办法了。找到一…

java 邮件 tls_通过TLS发送的Java邮件

java 邮件 tls抽象 本博客的目的是演示如何使用Java Mail通过具有TLS连接的SMTP服务器发送电子邮件。 免责声明 这篇文章仅供参考。 在使用所提供的任何信息之前,请认真思考。 从中学到东西,但最终自己做出决定,风险自负。 要求 我使用以下…

java中的break与continue用法

一、break break 的作用为跳出循环&#xff0c;执行循环外面的操作 &#xff08;1&#xff09;简单break public class Main {public static void main(String[] args) {int i0;for(;i<100;i){if(i2)break;}System.out.println(i);} } 输出结果&#xff1a;2 双重循环 publ…

java中的native关键字有什么作用?(java本地方法)

转自&#xff1a; http://zhidao.baidu.com/link?urlXu94DBMxXz3sJyCrG7G1sCmXoHuyuYx4DMG1x7UqYL7FhfFnqF7-Z9nxIQUpntPkqzaZ0xAyIjKIrEYrwIett_ 1、什么是Native Method 简单地讲&#xff0c;一个Native Method就是一个java调用非java代码的接口。一个Native Method是这样一…

php sessionid 重复,php_ session_id 限制同一用户同时登录

出于信息安全的考虑&#xff0c;希望给每个能进入系统的人员一个账户&#xff0c;而不是所有人共用一个账户&#xff0c;并且一个账户同时只能一人登陆。刚开始的做法是登陆加锁&#xff0c;当用户登陆之后&#xff0c;对此用户进行标记&#xff0c;若此用户未下线状态下进行第…