You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Dharanendra S. Pandit" <Dh...@netscape.net> on 2002/03/11 12:01:33 UTC
Help sought
Hi,
I'm facing a problem. Kindly provide me a solution.
Package log4j has a class file CategoryTester.class
Package log4j.child has a class file Bar.class
Package log4j.child.child1 has a class Bar1.class
The following lines are specified in a configuration file and read using
PropertyConfigurator .
log4j.category.log4j.CategoryTester=DEBUG, A2
# A2 is set to be a ConsoleAppender.
log4j.appender.A2=org.apache.log4j.ConsoleAppender
# A2 uses PatternLayout.
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#-----------------------------------------------------------------------------
log4j.category.log4j.child=DEBUG, A3
# A3 is set to be a RollingFileAppender
log4j.appender.A3=org.apache.log4j.RollingFileAppender
log4j.appender.A3.File=example.log
log4j.appender.A3.MaxFileSize=100KB
# Keep one backup file
log4j.appender.A3.MaxBackupIndex=1
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%p %t %c - %m%n
Bar.class has additivity turned to false using the method,
cat.setAdditivity( false ), where cat is of type Category.
The code for CategoryTester , Bar and Bar1 is mentioned below.
CLASS CATEGORYTESTER.JAVA
package log4j;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
import log4j.child.Bar;
public class CategoryTester{
static Category category = Category.getInstance(
CategoryTester.class.getName( ) );
public static void main(String[] args) {
new CategoryTester( args );
}
public CategoryTester( String args[] ){
// Set up a simple configuration that logs on the console.
// BasicConfigurator.configure();
PropertyConfigurator.configure(args[0]);
category.setAdditivity( false );
category.info("Entering application.");
Bar bar = new Bar();
bar.doIt();
category.info("Exiting application.");
}
}
CLASS BAR.JAVA
package log4j.child;
import org.apache.log4j.Category;
import log4j.child.child1.Bar1;
public class Bar {
static Category cat = Category.getInstance( Bar.class.getName( ) );
public void doIt() {
cat.setAdditivity( false );
new Bar1( ).doIt( );
cat.debug("Did it again in Bar!");
}
}
CLASS BAR1.JAVA
package log4j.child.child1;
import org.apache.log4j.Category;
public class Bar1 {
static Category cat = Category.getInstance( Bar1.class.getName( ) );
public void doIt() {
cat.debug("Did it again in Bar1!");
}
}
When I execute CategoryTester it throws,
log4j:ERROR No appenders could be found for category (log4j.child.Bar).
log4j:ERROR Please initialize the log4j system properly.
1. But, Bar1.java is able to log in example.log while Bar is not. Why
is it so?
2. If I need both to be logged into example.log file what changes I
need to make in the configuration file?
3. My intention is, the logging statements of Bar & Bar1 should not be
logged in ConsoleAppender which the CategoryTester uses but in the
"example.log" file. One work around for this is explicitly specify two
entries, one each for Bar and Bar1 in configuration file, to use
"example.log" file. But, may not be possible in practical situation.
If I have to specify that all the classes beneath child package need to
be logged into example.log file how could I achieve it?
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>