Configuring a colourful Logback
Logging colourful output came up recently in project I was working on. Here's how I typically configure logging from my Clojure codebases with a little colour on top.
There are a few features worth pointing out in the following file.
- We tell Emacs to use
sgml-mode
rather thanxml-mode
, which formats things aggressively. - We have Logback reload our configuration file automatically every 10 seconds, which is great for development where we might need to tweak our configuration.
- We log to the console (rather than a file) using ANSI colour codes (like
%blue(...)
and%yellow(...)
). - We ignore any message finer than
WARN
to silence noisy third-party libraries. - We override the default log level for specific namespaces with our final
<logger>
entries.
<!-- -*- mode: sgml -*- -->
<configuration scan="true" scanPeriod="10 seconds" debug="false">
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>%d{"HH:mm:ss.SSS"} %blue(%-5level) %yellow(%logger{36}) %msg%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
<logger name="invetica" level="ALL" />
<logger name="user" level="ALL" />
</configuration>