2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2015 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
5 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
8 import java
.io
.IOException
;
9 import java
.util
.logging
.Handler
;
10 import java
.util
.logging
.Logger
;
12 import org
.lttng
.ust
.agent
.jul
.LttngLogHandler
;
15 * Example application using the LTTng-UST Java JUL agent.
18 * Basically all that is required is to instantiate a {@link LttngLogHandler}
19 * and to attach it to a JUL {@link Logger}. Then use the Logger normally to log
20 * messages, which will be sent to UST as trace events.
23 * {@link Logger} names are used as event names on the UST side. This means that
24 * by enabling/disabling certain events in the tracing session, you are
25 * effectively enabling and disabling Loggers on the Java side. Note that this
26 * applies only to {@link LttngLogHandler}'s. If other handlers are attached to
27 * the Logger, those will continue logging events normally.
31 * To obtain LTTng trace events, you should run the following sequence of
36 * <li>$ lttng create</li>
37 * <li>$ lttng enable-event -j -a</li>
38 * <li>$ lttng start</li>
39 * <li>(run this program)</li>
40 * <li>$ lttng stop</li>
41 * <li>$ lttng view</li>
42 * <li>$ lttng destroy</li>
45 * @author Alexandre Montplaisir
46 * @author David Goulet
50 /** Class-wide JUL logger object */
51 private static final Logger LOGGER
= Logger
.getLogger(Hello
.class.getName());
57 * Command-line arguments
59 * If the required native libraries cannot be found. You may
60 * have to specify "-Djava.library.path=..." on the "java"
63 public static void main(String args
[]) throws IOException
{
65 /* Instantiate a LTTngLogHandler object, and attach it to our logger */
66 Handler lttngHandler
= new LttngLogHandler();
67 LOGGER
.addHandler(lttngHandler
);
69 /* Log events using the JUL Logger created before. */
70 LOGGER
.info("Hello World, the answer is " + 42);
71 LOGGER
.info("Another info event");
72 LOGGER
.severe("A severe event");
75 LOGGER
.removeHandler(lttngHandler
);
This page took 0.030967 seconds and 4 git commands to generate.