logback:
timestamp INFO msg...
timestamp WARN msg...
timestamp INFO msg...
classic java logging (JUL):
timestamp INFO msg...
timestamp WARNING msg...
timestamp INFO msg...
I prefer the WARNING level to be longer than INFO, so I can easily distinguish it visually when scanning log output.
You could specify different logback patterns to achieve what you want - you can send info level logging to an appender which uses a standard layout and then warn to a different appender which uses the word WARNING instead:
<configuration debug="true">
<appender name="info" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>DENY</onMatch>
<onMismatch>ACCEPT</onMismatch>
</filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
%d{"ISO8601", UTC} %p %m%n
</pattern>
</encoder>
</appender>
<appender name="warn" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>
%d{"ISO8601", UTC} WARNING %m%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="info"/>
<appender-ref ref="warn"/>
</root>
</configuration>
The %p
parameter is substituted with the original message log level so we keep that for the info pattern, for the warn pattern we don't use %p
but rather use the constant WARNING.
This config would sit in your logback.xml
file in resources root.
EDIT
Changed xml config to use filters and only have one root logger
The idea here is to filter out everything EXCEPT warn level for the first appender, and then on the second only accept warn level and override the log to show WARNING
sample output:
2018-11-08 10:52:40,460 WARNING Exception calculating properties for model(...)
2018-11-08 10:52:40,757 INFO Generating unique operation named: ...