希望有人可以帮助解决这个问题,因此基本上我正在使用log4j-1.2.17,抱歉,我无法将其更新为log4j2。 如标题所示,我需要执行以下操作,
我的 log4j.properties 文件如下所示
log4j.logger.com.ssl=INFO, Output
log4j.logger.com.ssl=INFO, Audit
log4j.appender.Output=org.apache.log4j.DailyRollingFileAppender
log4j.appender.Output.DatePattern='.'yyyy-MM-dd
log4j.appender.Output.File=/var/log/operational/operations.log
log4j.appender.Output.layout=org.apache.log4j.PatternLayout
log4j.appender.Output.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
log4j.appender.Output.Threshold=TRACE
log4j.appender.Output.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.Output.filter.1.StringToMatch=USER ACTION
log4j.appender.Output.filter.1.AcceptOnMatch=false
log4j.appender.Output.filter=org.apache.log4j.varia.DenyAllFilter
log4j.appender.Audit=org.apache.log4j.DailyRollingFileAppender
log4j.appender.Audit.DatePattern='.'yyyy-MM-dd
log4j.appender.Audit.File=/var/log/operational/audit.log
log4j.appender.Audit.Threshold=TRACE
log4j.appender.Audit.layout=org.apache.log4j.PatternLayout
log4j.appender.Audit.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %m (%c)%n
log4j.appender.Audit.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.Audit.filter.1.StringToMatch=USER ACTION
log4j.appender.Audit.filter.1.AcceptOnMatch=true
log4j.appender.Audit.filter=org.apache.log4j.varia.DenyAllFilter
在 Java代码中,我有类似的内容
private static final String AUDIT_LOG_PREFIX = "USER ACTION";
logger.info("Just testing if this appears before the one below it");
logger.info("[" + AUDIT_LOG_PREFIX + "] - User Details Updated by User : "+ r.getUserName());
我得到的日志输出如下,
operational.log
2018-11-22 10:55:31 INFO [http-nio-8080-exec-179] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
audit.log
2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] Just testing if this appears before the one below it (com.ssl.operational.action.EditDetailsActionBean)
2018-11-22 10:58:51 INFO [http-nio-8080-exec-192] [USER ACTION] - User Details Updated by User : adminuser
因此,我真的希望 audit.log 不显示第一个日志条目,而只显示带有USER ACTION字符串的条目。
任何帮助或建议将不胜感激,谢谢