简体   繁体   中英

How to control the log console output in log4j

I am new to JavaEE SSH environment, and currently I use log4j as my application's log system. But the problem is that if I set the log output level at DEBUG there are too many console output in MyEclipse, switch the output level to WARN will reduce the amount of the messages but also lost some information I interested in. So my question is how to let the log4j ONLY output ALL the log message generated by the Java file I am editing and DO NOT output ANY messages generated by others.

Assuming you are configuring log4j with a log4j.properties file, you can set a specific class or package to a different level like this:

log4j.logger.com.foo.MyClass=DEBUG

See http://logging.apache.org/log4j/1.2/manual.html for more introductory log4j stuff.

http://logging.apache.org/log4j/1.2/manual.html

You can configure the log-level of every Logger you created via Logger.getLogger("org.springframework") . You must search the configuration file for log4j.

Example for XML (from http://en.wikipedia.org/wiki/Log4j ):

 ... <logger name="org.springframework"> <level value="info"/> </logger> <!-- everything of spring was set to "info" but for class PropertyEditorRegistrySupport we want "debug" logging --> <logger name="org.springframework.beans.PropertyEditorRegistrySupport"> <level value="debug"/> </logger> 

Hope that helps.

I had the same issue whereby my log4j debug logging was being overwhelmed by Spring debugging in my JUnit unit tests (in Eclipse). I got around this by adding the following to my log4j properties file.

log4j.logger.org.springframework=FATAL

if you are running in the unix/linux environment, you can tail and grep the log file what exactly you are looking for. this is more flexible than modifying log4j configuration and much more powerful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM