I don't use config or xml files for configuring log4j as there no need to configure it deeply. I only need to print messages to the console. so I do this:
BasicConfigurator.configure();
and to print only info and higher messages I do this:
Logger LOG = Logger.getLogger(MyClass.class)
LOG.setLevel(Level.INFO);
But nevertheless I see debug messages in the console too. But I only need info and actually error messages to be printed.
How to do this?
UPD: I created a config file with the which contains, as described in the tutorial here: manual the following:
log4j.rootLogger=INFO, stdout
# 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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L %m%n
log4j.logger.com.messagedna.facade=INFO
log4j.logger.com.messagedna.receiver=INFO
log4j.logger.com.messagedna.util=INFO
log4j.logger.com.messagedna.parser=INFO
I put it to the com.messagedna
In every class I need logger in I wrote the following:
Properties props = new Properties();
try {
props.load(new FileInputStream("/log4j.properties"));
} catch (Exception e){
LOG.error(e);
}
PropertyConfigurator.configure(props);
but when I run my app I get the following:
log4j:WARN No appenders could be found for logger (com.messagedna.server.util.Config).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.