Commit | Line | Data |
---|---|---|
215610eb PP |
1 | --- |
2 | id: jul | |
86384750 | 3 | since: 2.4 |
215610eb PP |
4 | --- |
5 | ||
6 | Here's an example of tracing a Java application which is using | |
7 | **`java.util.logging`**: | |
8 | ||
9 | ~~~ java | |
10 | import java.util.logging.Logger; | |
11 | import org.lttng.ust.agent.LTTngAgent; | |
12 | ||
13 | public class Test | |
14 | { | |
15 | private static final int answer = 42; | |
16 | ||
17 | public static void main(String[] argv) throws Exception | |
18 | { | |
19 | // create a logger | |
20 | Logger logger = Logger.getLogger("jello"); | |
21 | ||
22 | // call this as soon as possible (before logging) | |
23 | LTTngAgent lttngAgent = LTTngAgent.getLTTngAgent(); | |
24 | ||
25 | // log at will! | |
26 | logger.info("some info"); | |
27 | logger.warning("some warning"); | |
28 | Thread.sleep(500); | |
29 | logger.finer("finer information; the answer is " + answer); | |
30 | Thread.sleep(123); | |
31 | logger.severe("error!"); | |
32 | ||
33 | // not mandatory, but cleaner | |
34 | lttngAgent.dispose(); | |
35 | } | |
36 | } | |
37 | ~~~ | |
38 | ||
39 | The LTTng-UST Java agent is packaged in a JAR file named | |
40 | `liblttng-ust-agent.jar` It is typically located in | |
41 | `/usr/lib/lttng/java`. To compile the snippet above | |
42 | (saved as `Test.java`), do: | |
43 | ||
44 | <pre class="term"> | |
45 | javac -cp /usr/lib/lttng/java/liblttng-ust-agent.jar Test.java | |
46 | </pre> | |
47 | ||
48 | You can run the resulting compiled class like this: | |
49 | ||
50 | <pre class="term"> | |
51 | java -cp /usr/lib/lttng/java/liblttng-ust-agent.jar:. Test | |
52 | </pre> | |
53 | ||
54 | <div class="tip"> | |
55 | <p> | |
56 | <span class="t">Note:</span><a href="http://openjdk.java.net/" class="ext">OpenJDK</a> 7 | |
57 | is used for development and continuous integration, thus this | |
58 | version is directly supported. However, the LTTng-UST Java agent has | |
59 | also been tested with OpenJDK 6. | |
60 | </p> | |
61 | </div> |