martes, 9 de junio de 2009

Simplest log4j configuration

The simplest way to configure log4j without a file, and with java code (specially handy when you want to use log4j for a small java app, and want to get rid of the warnings showed by the logger).

Properties conf = new Properties();

conf.put("log4j.rootLogger", "debug, myAppender");
conf.put("log4j.appender.myAppender", "org.apache.log4j.ConsoleAppender");
conf.put("log4j.appender.myAppender.layout", "org.apache.log4j.SimpleLayout");
PropertyConfigurator.configure(conf);

No hay comentarios: