Show Logback Configuration Status with Groovy Configuration

Logback is a SLF4J API implementation for logging messages in Java and Groovy. We can configure Logback with a Groovy configuration file. The file is a Groovy script and allows for a nice an clean way (no XML) to configure Logback. If we want to show the logging configuration and see how Logback is configured we must add a StatusListener implementation in our configuration. The StatusListener implementation prints out the configuration when our application starts. Logback provides a StatusListener for outputting the information to system out or system error streams (OnConsoleStatusListener and OnErrorConsoleStatusListener). If we want to disable any status messages we use the NopStatusListener class.

In the following example configuration file we define the status listener with the statusListener method. We use the OnConsoleStatusListener in our example:

If we run our Java or Groovy application with this configuration we get the following information in our console:

Alternatively we can use the Java system property logback.statusListenerClass when we run our application. We must provide the full class name for the StatusListener implementation. This will overrule any status listeners that are defined in configuration files.

Written with Logback 1.1.3.

Original article

This entry was posted in Coding and tagged , , by mrhaki. Bookmark the permalink.

About mrhaki

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in. You can contact me via Google+ or @mrhaki.

One thought on “Show Logback Configuration Status with Groovy Configuration

  1. WOW ! You read minds too! I was just trying to figure this prob.out less than 4 hrs ago. Ur insights really matter to me, makes my day seem a whole lot more rosy thx

Leave a Reply

Your email address will not be published. Required fields are marked *