I have a Tomcat server running a Spring-based servlet.
I've set up [project root]/src/log4j.properties
file as below:
# Root logger option
log4j.rootLogger=WARN, stdout
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d{HH:mm:ss} %m [%c{3}:%L]%n
log4j.logger.com.martincarney.bugTracker=DEBUG
log4j.logger.com.martincarney.bugTracker.controller=ERROR
This correctly logs my own code just fine, but doesn't seem to have any effect on logging from within the various libraries I'm using. For example, I still get INFO logs from org.apache.*
to the Eclipse console error stream during Tomcat startup, even if I add log4j.logger.org.apache=WARN
to my log4j.properties.
I'm using slf4j-api
and slf4j-log4j
jars, obtained through Maven.
How can I take control of logging levels and targets outside my own code?
Some libraries use other logging frameworks like
java.util.logging
.You could redirect logging with SLF4J, see SLF4J - Bridging legacy APIs:
Redirection for Jakarta Commons Logging:
Redirection for
java.util.Logging
(SLF4J API):For configuration of
java.util.Logging
see JUL API.Some libraries like Apache CXF supports more than one logging framework, see Apache CXF - Debugging and Logging .