LOG4J: Modify logged message using custom appender

前端 未结 4 567
一生所求
一生所求 2020-12-01 06:41

For security reasons, I need to look at every logged message in my app and possibly modify it before it goes to the log file. I figured I could write a custom appender (exte

4条回答
  •  無奈伤痛
    2020-12-01 07:31

    I'd go for creating a delegate class for Logger and change all imports from org.apache.log4j.Logger to your.own.Logger. It's a simple and automatic process — since you consider changing logger calls in the code, I figure you have full access to source code. In the delegate you'd call exactly the methods from log4j Logger, but meddle with the strings first to your heart's content.

    I've browsed through the code and prior to version 1.2.15 creating a new LoggingEvent from an existing one is impossible without digging through half of the library. From 1.2.15 on there's no problem with it.

提交回复
热议问题