It can be annoying to have each third-party library or framework in your application logging to a different logfile. slf4j with its various adapters enables you to collect logging events from various APIs (org.slf4j.api, java.util.logging, org.apache.commons.logging) and redirect them to a logging backend of your choice.
I've always preferred log4j or, more recently, logback over java.util.logging, so after working with Glassfish v3 for a while, I tried to tweak it to use logback over slf4j and the jul-to-slf4j bridge.
To redirect java.util.logging used by Glassfish v3, you put the following libs on your classpath:
The problem with Glassfish is:
- You need to take care of its class loader hierarchy and make sure that the logging jars get picked up early enough.
- Glassfish does some all-too-clever logger manipulation in its LogManagerService which will get in your way if you don't like the Glassfish defaults: It redirects all System.out messages to a logger.
- Put the logging libs in [install-root]/lib/endorsed.
- Build a JAR containing your logback.xml configuration and put it in the same place.
- Edit an entry in [instance-root]/config/logging.properties, setting
handlers = org.slf4j.bridge.SLF4JBridgeHandler