My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are my logger choices and what would you recommend. Ideally the configuration would be simple (one config file for Hibernate, Spring and my code).
I use the Apache Commons Logging api, with a log4j config file (the log4j config file is simple, easy for a novice to understand and has numerous examples to work from.
I prefer using the commons logging API because its agnostic about its configuration file. It can be configured via file formats for any number of popular logging packages.
Here's a simple log4j setup that will print out debug info for your own packages, INFO level for spring and hibernate, and WARN for everything else:
# Global logging configuration
log4j.rootLogger=WARN, stdout
log4j.category.org.mydomain.org=DEBUG
log4j.category.org.hibernate=INFO
log4j.category.org.springframework=INFO
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] %c - %m%n
When building applications out of various frameworks you often need to wrap existing loggers, be they log4j or JUL or JULI or whatever. The standard application for this is the Simple Logging Facade for Java (SLF4J). Even if your app doesn't need SLF4J now you may later want to add a library that does need it, and it's your best hope for one config file in the long run.
With that in mind you should stick to logging packages that SLF4J supports, but usually it boils down to java.util.logging (JUL) or Apache's log4j. This has been a subject for debate for some time and you can find many opinions on both sides.
Personally, I think it's unfortunate that Java logging is in this situation, and I'll use whatever gives me the least pain for the situation.
Nobody ever got fired for choosing log4j.
Also check out slf4j.
Hibernate already relies on SLF4J. Unless I am mistaken, the current version of Spring relies on commons-logging but the next version will be using SLF4J as well. Anyway, you could consolidate all logging through SLF4J (see the section on jcl-over-slf4j.jar). Once that is done, you could choose any of java.util.logging, log4j or logback as your underlying logging framework.
Generally speaking, Commons Logging is unnecessary and a bad choice for web applications (and standalone applications). Some good writing on why: