How can I check loading log4j.properties?
I am using log4j (compile slf4j group, runtime group logback) with configuration in log4j.properties file.
I think I configured it correctly with these options
log4j.rootLogger=INFO, stdout, file
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=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.stdout.threshold=info
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/home/user/logging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=20
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-5p [%d{dd.MM.yy HH:mm:ss}] %C{1} - %m [thread: %t]\n
log4j.appender.file.threshold=info
But when I run a debug message like
logger.debug("foo")
I see output in the console that doesn't match my pattern.
The next problem is that there is nothing in the file (/home/user/logging.log), so I think my properties file is not loaded and does not know how to restore it.
I put my log4j.properties file in the root level of my eclipse project, in resources (src / main / resources), but didn't change anything. I have a Project folder on the classpath.
EDIT: The problem was that I am using Logback
( http://logback.qos.ch/ ) as my Logger runtime, but this library is using a config file logback.xml
, not log4j.properties
a library org.apache.log4j
.
source to share
According to the logging level INFO
< DEBUG
, so logger.debug("foo")
will not be logged.
This is the logging level in the order most specific to the least
DEBUG > INFO > WARN > ERROR > FATAL
If INFO
enabled, the logging level below it will also be enabled.
Try
log4j.rootLogger=DEBUG, stdout, file
...
log4j.appender.stdout.threshold=debug
...
log4j.appender.file.threshold=debug
source to share