日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

intro to Apache Log4j 2

發布時間:2023/12/3 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.

總結

以上是生活随笔為你收集整理的intro to Apache Log4j 2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。