Jake has an excellent point. Here is an example of how such code would
look like:
log4j.rootLogger=debug, stdout
log4j.logger.com.myproject=info
As you can see the logger for the package com.myproject only has info
behind it. If you would say log4j.logger.com.myproject=info, stdout then
any log message will be printed twice.
Martyn
Jacob Kjome schreef:
On Wed, 13 Feb 2008 16:51:15 +0100
Martyn Hiemstra <[EMAIL PROTECTED]> wrote:
It is very simple. When you use log4j.rootLogger=debug you must ask
yourself, how is log4j suppost to know which appender to use?
For each logger you have to indicate which appender to use so use
this instead.
log4j.rootLogger=debug, stdout
The above example is correct but, just to be clear, you don't need to
add the appender to every logger. If the child logger is already
ineriting the appender from a parent, then it shouldn't be added to
the child unless the child is marked as using
log4j.additivity.com.my.child.LoggerName=false. Otherwise, you will
end up with duplicate log messages.
Jake
Then it should work.
Martyn
Hi folks -
I'm frustrated in trying to control the run-time configuration of
Log4j in
my standalone application. I have log4j-1.2.13.jar in my classpath. I
have a log4j.properties file configured as shown below. It seems
that I
have no idea where to place the property file in my classpath for
log4j to
find/use it. Right now, it seems that no matter where I put it the
logging level is always on INFO, In fact, it's on INFO even if I
completely delete the log4j.properties file from the project!
Please help me figure out how to properly control the logging level
using
log4j.properties file - like the one below... I would liket to set the
package level control to DEBUG or INFO, etc. Where do I put it,
and how
do I instruct logging framework to find and use this config file.
log4j.properties file - currently located in /target/classes directory:
-------------------------------------------------------------------------------------------------------
### direct log messages to stdout ###
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=%d{ABSOLUTE} %5p
%c{1}:%L -
%m%n
### set log levels - for more verbose logging change 'info' to
'debug' ###
log4j.rootLogger=debug
### debug your specific package or classes with the following example
log4j.logger.com.ibm.cods.batch.common.processor.email=debug
-------------------------------------------------------------------------------------------------------
My program has the following statements in it:
-------------------------------------------------------------------------------------------------------
package com.ibm.cods.batch.common.processor.email;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
public class Log4J_TestHarness extends TestCase {
private static org.apache.log4j.Logger log =
Logger.getLogger(Log4J_TestHarness.class);
protected void setUp() throws Exception {
super.setUp();
}
public void testLog4J_Configuration() {
log.info(">>>>>>>>>>> starting new test case:
testLog4J_Configuration()");
log.debug("hello from DEBUG!");
log.info("<<<<<<<<<<<< end test case:
testLog4J_Configuration()");
}
}
-------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]