ZRJ
ZRJ

Reputation: 181

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.

Upvotes: 0

Views: 2437

Answers (4)

mojo
mojo

Reputation: 1078

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

Upvotes: 0

ligerdave
ligerdave

Reputation: 764

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

Upvotes: 0

ollins
ollins

Reputation: 1849

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.

Upvotes: 2

Jeremiah Orr
Jeremiah Orr

Reputation: 2630

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.

Upvotes: 3

Related Questions