如何在Log4j 2.2中使用LoggingEvent类 [英] How to use LoggingEvent class with log4j 2.2

查看:85
本文介绍了如何在Log4j 2.2中使用LoggingEvent类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Log4j 1.x迁移到Log4j2.x.因此,我正在尝试使用

I want to migrate from Log4j 1.x to Log4j 2.x. So I'm trying to use log4j-1.2-api.jar as mentioned here. My application has an implementation of org.apache.log4j.spi.LoggingEvent, but I cannot find a way to use LoggingEvent with the log4j 2.x api bridge. Is there anyway that I can use LoggingEvent with log4j 2.2 ?

谢谢.

推荐答案

在内部,log4j使用LogEvent将所有数据(日志消息,线程名称,时间戳,标记,记录器名称等)传送到附加程序,其中它们可能会出现在输出中.

Internally, log4j uses a LogEvent to carry all the data pieces (the log message, thread name, timestamp, markers, logger name, etc) to the appenders where they may appear in the output.

Log4j日志事件仅供内部使用,不能设计为由应用程序扩展.例如,异步记录器使用LogEvent接口的特殊实现来满足基础LMAX Disruptor库的要求.扩展它并不容易.

Log4j log events are designed for internal use only and are not designed to be extended by applications. For example, Async Loggers use a specialized implementation of the LogEvent interface to meet the requirements of the underlying LMAX Disruptor library. It will not be easy to extend this.

您的用例对我来说并不明确,但是例如,如果您要开发一个自定义追加器,而该追加器需要LogEvent接口中不存在的自定义数据,则可以考虑使用ThreadContext映射将数据从您的应用传递到自定义追加程序,而不是尝试使用自定义日志事件.

Your use case is not clear to me, but if for example you want to develop a custom appender which needs custom data not present in the LogEvent interface, you can consider using the ThreadContext map to pass data from your app to the custom appender, rather than trying to use a custom log event.

这篇关于如何在Log4j 2.2中使用LoggingEvent类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆