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.

  1. We tell Emacs to use sgml-mode rather than xml-mode, which formats things aggressively.
  2. We have Logback reload our configuration file automatically every 10 seconds, which is great for development where we might need to tweak our configuration.
  3. We log to the console (rather than a file) using ANSI colour codes (like %blue(...) and %yellow(...)).
  4. We ignore any message finer than WARN to silence noisy third-party libraries.
  5. 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">
      <pattern>%d{"HH:mm:ss.SSS"} %blue(%-5level) %yellow(%logger{36}) %msg%n</pattern>

  <root level="WARN">
    <appender-ref ref="STDOUT" />

  <logger name="invetica" level="ALL" />
  <logger name="user" level="ALL" />