Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I unify logging formats from the java stack

Using a Jetty web server, started from maven, which includes iBatis, Spring, Jersey, a little of this and a little of that, I get logging output with a host of formats.

Some are from maven:

[INFO] [war:war]
[INFO] Exploding webapp...

Some are from Jetty:

2009-03-25 21:01:27.781::INFO:  jetty-6.1.15
2009-03-25 21:01:28.218:/example:INFO:  Initializing Spring root WebApplicationContext

Some are from Spring:

INFO  ContextLoader - Root WebApplicationContext: initialization started (189)
INFO  XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml] (323)

Some are from Jersey:

Mar 25, 2009 9:01:29 PM com.sun.jersey.spi.spring.container.SpringComponentProviderFactory register

still others are from my code:

INFO  ExampleApp - [User@14ef239 ...stuff] (69)

I expect they're all using standard logging packages (log4j, commons-logging, java-logging...)

  • Is it possible, and what is the easiest way to configure all of them to use the same format?
  • Is there any benefit to leaving them in varying formats?
  • like image 367
    Chadwick Avatar asked Mar 26 '09 01:03

    Chadwick


    1 Answers

    This is possible using the logback library and its bridges. It basically consists to remove any log4j commons or alike jars from the classpath, stick logback jar file and bridges jars for log4j and alike. Spring, jersey and maven will use the bridge factories to instantiate loggers which in turn will use logbak producing unified logging.

    Check http://logback.qos.ch/ and http://www.slf4j.org/legacy.html

    The key are the bridges which link other log utilities with a single global logger.

    like image 120
    Miquel Avatar answered Oct 05 '22 23:10

    Miquel