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

本文是小编为大家收集整理的关于如何使用Log4j 2.2的LoggingEvent类的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想从log4j 1.x迁移到log4j 2.x.因此,我正在尝试使用log4j-1.2-api.jar,如上所述在这里 .我的应用程序具有org.apache.log4j.spi.LoggingEvent的实现,但是我找不到使用Log4J 2.x API桥的LoggingEvent的方法.无论如何,我可以使用log4j 2.2使用loggingevent?

谢谢.

推荐答案

在内部,log4j使用凸钳将所有数据件(日志消息,线程名称,时间戳,标记,logger名称等)运送到可能出现在输出中的附录.

log4j日志事件仅用于内部用途,并不旨在通过应用程序扩展.例如,异步记录仪使用凸点接口的专门实现来满足基础LMAX拆卸器库的要求.扩展它并不容易.

您的用例对我来说尚不清楚,但是如果例如,您要开发一个需要自定义数据的自定义应用程序,则可以考虑使用ThreadContext映射将数据从应用程序传递到自定义appender,而不是尝试使用自定义日志事件.

其他推荐答案

升级log4j时,我只需使用 logevent 而不是 loggingevent .

我已删除附录将其替换为 AbstractAppender . AppenderSkeleton的s append(LoggingEvent event)方法出现在AbstractAppender AS append(LogEvent event)中,这是我使用LogEvent而不是LoggingEvent的提示.

.

本文地址:https://www.itbaoku.cn/post/1574832.html

问题描述

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 ?

Thanks.

推荐答案

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

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.

其他推荐答案

When upgrading Log4j, I simply used LogEvent instead of LoggingEvent.

I had removed AppenderSkeleton and replaced it with AbstractAppender. AppenderSkeleton's append(LoggingEvent event) method appears in AbstractAppender as append(LogEvent event), which was my cue to use LogEvent instead of LoggingEvent.