Commit | Line | Data |
---|---|---|
501f6777 | 1 | /* |
d60dfbe4 | 2 | * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> |
501f6777 CB |
3 | * Copyright (C) 2014 - Christian Babeux <christian.babeux@efficios.com> |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | * of this software and associated documentation files (the "Software"), to | |
7 | * deal in the Software without restriction, including without limitation the | |
8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 | * sell copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 | * IN THE SOFTWARE. | |
22 | */ | |
501f6777 | 23 | |
d60dfbe4 AM |
24 | import java.io.IOException; |
25 | ||
26 | import org.apache.log4j.Appender; | |
501f6777 | 27 | import org.apache.log4j.BasicConfigurator; |
8685da11 | 28 | import org.apache.log4j.Logger; |
d60dfbe4 | 29 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
501f6777 | 30 | |
5bfeaeca AM |
31 | /** |
32 | * Example application using the LTTng-UST Java JUL agent. | |
33 | * | |
d60dfbe4 | 34 | * @author Alexandre Montplaisir |
5bfeaeca AM |
35 | * @author Christian Babeux |
36 | */ | |
37 | public class Hello { | |
38 | ||
d60dfbe4 | 39 | private static final Logger HELLO_LOG = Logger.getLogger(Hello.class); |
501f6777 | 40 | |
5bfeaeca AM |
41 | /** |
42 | * Application start | |
43 | * | |
44 | * @param args | |
45 | * Command-line arguments | |
d60dfbe4 AM |
46 | * @throws IOException |
47 | * @throws InterruptedException | |
5bfeaeca | 48 | */ |
d60dfbe4 AM |
49 | public static void main(String args[]) throws IOException, InterruptedException { |
50 | /* Start with the default Log4j configuration, which logs to console */ | |
501f6777 | 51 | BasicConfigurator.configure(); |
d60dfbe4 AM |
52 | |
53 | /* | |
54 | * Add a LTTng log appender to the logger, which will also send the | |
55 | * logged events to UST. | |
56 | */ | |
57 | Appender lttngAppender = new LttngLogAppender(); | |
58 | HELLO_LOG.addAppender(lttngAppender); | |
59 | ||
60 | /* | |
61 | * Here we've set up the appender programmatically, but it could also be | |
62 | * defined at runtime, by reading a configuration file for example: | |
63 | */ | |
64 | // PropertyConfigurator.configure(fileName); | |
501f6777 CB |
65 | |
66 | /* | |
67 | * Gives you time to do some lttng commands before any event is hit. | |
68 | */ | |
69 | Thread.sleep(5000); | |
70 | ||
d60dfbe4 AM |
71 | /* Trigger a tracing event using the Log4j Logger created before. */ |
72 | HELLO_LOG.info("Hello World, the answer is " + 42); | |
501f6777 | 73 | |
d60dfbe4 | 74 | System.out.println("Firing second event in 5 seconds..."); |
501f6777 | 75 | Thread.sleep(5000); |
d60dfbe4 | 76 | HELLO_LOG.info("Hello World delayed..."); |
8685da11 | 77 | |
d60dfbe4 | 78 | lttngAppender.close(); |
501f6777 CB |
79 | } |
80 | } |