| 1 | The agent can be built in three different configurations: |
| 2 | |
| 3 | 1) Java agent with JUL support: |
| 4 | |
| 5 | $ ./configure --enable-java-agent-jul |
| 6 | |
| 7 | 2) Java agent with Log4j support: |
| 8 | |
| 9 | $ export CLASSPATH=$CLASSPATH:/path/to/log4j.jar |
| 10 | $ ./configure --enable-java-agent-log4j |
| 11 | |
| 12 | 3) Java agent with JUL + Log4j support |
| 13 | |
| 14 | $ export CLASSPATH=$CLASSPATH:/path/to/log4j.jar |
| 15 | $ ./configure --enable-java-agent-all |
| 16 | |
| 17 | To build the agent with log4j support, make sure that the log4j jar |
| 18 | is in your Java classpath. |
| 19 | |
| 20 | The configure script will automatically detect the appropriate Java |
| 21 | binaries to use in order to build the Java agent. |
| 22 | |
| 23 | Enabling the JUL support will build a "lttng-ust-agent-jul.jar" file. Enabling |
| 24 | the log4j support will build a "lttng-ust-agent-log4j.jar". Both of these jars |
| 25 | depend on a third "lttng-ust-agent-common.jar", which will always be built. |
| 26 | |
| 27 | All these archives will be installed in the arch-agnostic "$prefix/share/java" |
| 28 | path, e.g: "/usr/share/java". You need to make sure the .jar for the logging |
| 29 | API you want to use (either lttng-ust-agent-jul.jar or -log4j.jar) is on your |
| 30 | application's classpath. |
| 31 | |
| 32 | Both logging libraries also require an architecture-specific shared object |
| 33 | (e.g: "liblttng-ust-jul-jni.so"), which is installed by the build system when |
| 34 | doing "make install". Make sure that your Java application can find this shared |
| 35 | object with the "java.library.path" property. |
| 36 | |
| 37 | In order to enable the agent in your Java application, you simply have to add |
| 38 | this as early as you can in the runtime process. |
| 39 | |
| 40 | import org.lttng.ust.agent.LTTngAgent; |
| 41 | [...] |
| 42 | private static LTTngAgent lttngAgent; |
| 43 | [...] |
| 44 | lttngAgent = LTTngAgent.getLTTngAgent(); |
| 45 | |
| 46 | This will initialize automatically the singleton LTTngAgent, and will |
| 47 | return when the session daemon registration is done. If no session daemon is |
| 48 | available, the execution will continue and the agent will retry every |
| 49 | 3 seconds. |