Tuesday, 20 August 2013

Incredibly simple Log4j 2.0 example not working

Incredibly simple Log4j 2.0 example not working

This is a stupidly simple example, and yet for some reason it's not
working. I must be missing something obvious.
I am trying to make a very simple log4j 2.0 example program. I have added
these two jars to the classpath:
log4j-api-2.0-beta8.jar
log4j-core-2.0-beta8.jar
And have done the simplest example possible, using the default configuration:
package testlog;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TestLog {
static Logger logger = LogManager.getLogger(TestLog.class.getName());
public static void main(String[] args) {
logger.trace("Hello World");
System.out.println("Test over");
}
}
But for some reason, all I get is 'Test over', I never get the Hello
World, anywhere I can find anyway. Am I looking in the wrong place? It;s
my understanding that with the default configuration it should be printed
to the console, with the 'Test Over'. I have changed the log level to
info, still the same. I have tried pulling out the Logger functionality
into a class, still the same. I am following this tutorial on the log4j
documentation page:
http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration
I can't understand what could possibly be wrong. Could anyone shed any
light on what I've done wrong? Thanks in advance.

No comments:

Post a Comment