Hello there Logback users. An application I’m responsible uses logback for its
internal logging. It logs to various files at various levels. I’ve extended it
successfully to reformat certain log messages and save them into a new log
called “combined-audit.log”. This is all within a single JVM, logging to a file
on a local filesystem.
The reason for the three loggers/appenders is that I want to log from three
different packages, at different levels, filter each differently, and encode
each differently. This is all necessary because I cannot make changes to the
app itself, so I’m trying to use Logback to accomplish my needs.
The below configuration works in Logback 1.1.3 and not in Logback 1.2.3.
In Logback 1.2.3, only messages from one of the three loggers are logged to the
single file. When I change the file name to three different files, messages
from each logger are in each file.
I read through release notes from 1.1.3 to 1.2.3 and nothing jumped out at me
as having the potential to change this behavior.
Is this a supported configuration in 1.2.3? Does anyone have any ideas for how
to accomplish the objective?
<!-- Appends app audit messages to combined audit log -->
<appender name="COMBINED_AUDIT" class="ch.qos.logback.core.FileAppender">
<File>${logging.directory}/combined-audit.log</File>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>%date{ISO8601}|%mdc{m.remote_addr}|%mdc{m.jsessionid}||%msg%n</Pattern>
</encoder>
</appender>
<logger name="j.k.l" level="ALL" additivity="false">
<appender-ref ref="COMBINED_AUDIT"/>
</logger>
<!-- Appends LDAP auth messages to combined audit log -->
<appender name="COMBINED_LDAP" class="ch.qos.logback.core.FileAppender">
<File>${logging.directory}/combined-audit.log</File>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>%date{ISO8601}|%mdc{m.remote_addr}|%mdc{m.jsessionid}|%replace(%replace(%replace(%msg){'^.*resultCode=',''}){',.*identifier=','|'}){',
context=.*$',''}|LDAP|||%n</Pattern>
</encoder>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>return message.contains("authenticate
response=");</expression>
</evaluator>
<OnMatch>ACCEPT</OnMatch>
<OnMismatch>DENY</OnMismatch>
</filter>
</appender>
<logger name="a.b.c.d" level="DEBUG" additivity="false">
<appender-ref ref="COMBINED_LDAP"/>
</logger>
<!-- Appends LDAP invalid username messages to combined audit log -->
<appender name="COMBINED_INVALID_USERNAME"
class="ch.qos.logback.core.FileAppender">
<File>${logging.directory}/combined-audit.log</File>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<charset>UTF-8</charset>
<Pattern>%date{ISO8601}|%mdc{m.remote_addr}|%mdc{m.jsessionid}|INVALID_USERNAME||LDAP|||%n</Pattern>
</encoder>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>return message.contains("failed using
filter=");</expression>
</evaluator>
<OnMatch>ACCEPT</OnMatch>
<OnMismatch>DENY</OnMismatch>
</filter>
</appender>
<logger name="v.w.x.y.z" level="INFO" additivity="false">
<appender-ref ref="COMBINED_INVALID_USERNAME"/>
</logger>
_______________________________________________
logback-user mailing list
[email protected]
http://mailman.qos.ch/mailman/listinfo/logback-user