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