Logback and webapplications

Lately I prefer to use Logback for logging purposes. Logback natively supports slf4j, a log abstraction api through other logging frameworks all can log to a logging framework of your choice.
When using logback in webapplication and you want your logging configuration file outside of your app you can set a systemproperty to point to the location.
However if you want it configured like you are used to do with Spring, log4j and the log4j servletcontext listener, you have to write the context listener yourself.
It’s a bit silly to do that again for every webapplication. So here it is, the logback-webfragment.
The logback-webfragment is a Servlet 3.x webfragment configered to be loaded before other fragments. It takes a location from a web.xml configparameter and loads the configuration from there. Optionally you can add another context parameter to enable one of the 5 default configurations I’ve added.
The idea for the code of the listener is taken from this ticket in logbacks issuetracker. Currently logback-webfragment will only work for Java 1.7 and higher. The maven artifact name is named aaa-logback-webfragment. The aaa is there to increase the chance that the webfragment is loaded before others that are also configured to be loaded first.
In analogy to logback itself the webfragments license is EPL. It is not yet in maven central repo. Maybe I have to test it a bit more.

%d bloggers like this: