6 LTTng features an Apache log4j 1.2 agent, which means your existing
7 Java applications using log4j 1.2 for logging can record events to
8 LTTng traces with just a minor source code modification.
12 <span class="t">Note:</span>This version of LTTng does not
20 import org.apache.log4j.Logger;
21 import org.apache.log4j.BasicConfigurator;
22 import org.lttng.ust.agent.LTTngAgent;
26 private static final int answer = 42;
28 public static void main(String[] argv) throws Exception
30 // create and configure a logger
31 Logger logger = Logger.getLogger(Test.class);
32 BasicConfigurator.configure();
34 // call this as soon as possible (before logging)
35 LTTngAgent lttngAgent = LTTngAgent.getLTTngAgent();
38 logger.info("some info");
39 logger.warn("some warning");
41 logger.debug("debug information; the answer is " + answer);
43 logger.error("error!");
44 logger.fatal("fatal error!");
46 // not mandatory, but cleaner
52 To compile the snippet above, do:
55 javac -cp /usr/lib/lttng/java/liblttng-ust-agent.jar:$LOG4JCP Test.java
58 where `$LOG4JCP` is the log4j 1.2 JAR file path.
60 You can run the resulting compiled class like this:
63 java -cp /usr/lib/lttng/java/liblttng-ust-agent.jar:$LOG4JCP:. Test