Log4j - filtering out logs for current project only
Have log4j.properties
file, that logs more than I expect,in particular, it logs events for Spring libraries.
Is it some filtering param,that specify what classes(project or namespace) should be logged?
Thank you.
Yes, create a logger entry that uses the name of your package.
log4j.logger.com.my.package=INFO
Set your appender to a more verbose setting and set the root appender to a higher level like ERROR or WARN.
log4j.rootLogger=ERROR, stdout
See this post: Log4j | Updating the Log Level for the Appender
From the log4j manual:
# Print only messages of level WARN or above in the package com.foo.
log4j.logger.com.foo=WARN
Replace com.foo
with the one that want to be ignored and set the logging level to some high value like WARN
or ERROR
.
I found another way of doing this.
I was having issues that when I was using level DEBUG or higher, the libs I used in my project were making it to the console. It's better to properly configure your project, but you can get by just disabling the logger for a specific package.
In the snippet below, all packages that start with org.* were disabled. Did the job for me. Found this at the manual: http://logging.apache.org/log4j/1.2/manual.html
log4j.rootLogger=INFO, stdout
# Disables logger for all org.* packages
log4j.logger.org=OFF
精彩评论