How to use LoggingEvent class with log4j 2.2

后端 未结 2 669
春和景丽
春和景丽 2021-01-18 00:36

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

相关标签:
2条回答
  • 2021-01-18 01:05

    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.

    0 讨论(0)
  • 2021-01-18 01:20

    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.

    0 讨论(0)
提交回复
热议问题