Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why apache.commons.logging.Log won't log Debug level?

I have a J2SE desktop app, and I'm trying to understand how to use apache commons logging. I have the following properties file in my project, using latest apache commons logging:

commons-logging.properties:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

#Priorities are: DEBUG, INFO, WARN, ERROR, or FATAL.
log4j.rootCategory=DEBUG
log4j.appender.appender.Threshold=DEBUG

log4j.properties:

log4j.rootLogger=TRACE

logging.properties:

# jdk handlers
handlers=java.util.logging.ConsoleHandler java.util.logging.FileHandler

# default log level FINE=ERROR FINER= FINEST=
.level=FINEST
java.util.logging.ConsoleHandler.level=FINEST

# log file name for the FileHandler
java.util.logging.FileHandler.pattern=gef_debug.log

And, even everything set to FINEST or TRACE, I still only the log for info and error on my console.

Any idea what's wrong here?

--

by the way, I'm in a existing old project, so maybe there's some configuration somewhere that I don't know about, that is blocking my log... :/ But only for the DEBUG level.

like image 615
The Student Avatar asked Oct 12 '25 08:10

The Student


1 Answers

org.apache.commons.logging.Log= org.apache.commons.logging.impl.Jdk14Logger

I think this line means you are using Jdk14Logger, not Log4j.

Jdk14Logger reads the file log-config.properties. Just create it in the application classpath and set it up. For example:

# The following creates the console handler
handlers=java.util.logging.ConsoleHandler
# Set the default logging level for the root logger
.level=FINEST
# Set the default logging level
java.util.logging.ConsoleHandler.level=ALL

# Set the default formatter
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

You can also change the logger to Log4j by changing the first line of the commons-logging.properties to org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger.

By doing so you'll be using Log4J logger that reads from the log4j.properties so you'll need to add the console handler to it.

You can take a look to several log implementations here.

like image 198
Rui Lopes Avatar answered Oct 14 '25 21:10

Rui Lopes