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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With