How to use LoggingEvent class with log4j 2.2

2020-04-07 03:03发布

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.

1条回答
Viruses.
2楼-- · 2020-04-07 03:12

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.

查看更多
登录 后发表回答