Commit | Line | Data |
---|---|---|
504d4ace | 1 | /* |
0b7af945 | 2 | * Copyright (C) 2015 - Michael Jeanson <dgoulet@efficios.com> |
504d4ace DG |
3 | * Copyright (C) 2014 - David Goulet <dgoulet@efficios.com> |
4 | * Christian Babeux <christian.babeux@efficios.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License, version 2 only, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
19 | ||
20 | import java.io.IOException; | |
21 | import java.lang.Integer; | |
22 | ||
0b7af945 | 23 | import org.apache.log4j.Appender; |
504d4ace | 24 | import org.apache.log4j.BasicConfigurator; |
0b7af945 | 25 | import org.apache.log4j.Logger; |
f59a892f | 26 | import org.apache.log4j.Level; |
0b7af945 | 27 | import org.lttng.ust.agent.log4j.LttngLogAppender; |
504d4ace | 28 | |
0b7af945 | 29 | public class JTestLTTng { |
504d4ace | 30 | |
0b7af945 MJ |
31 | /** |
32 | * Application start | |
33 | * | |
34 | * @param args | |
35 | * Command-line arguments | |
36 | * @throws IOException | |
37 | * @throws InterruptedException | |
38 | */ | |
39 | public static void main(String args[]) throws IOException, InterruptedException { | |
504d4ace | 40 | |
504d4ace DG |
41 | Logger lttng = Logger.getLogger("log4j-event"); |
42 | Logger lttng2 = Logger.getLogger("log4j-event-2"); | |
0b7af945 | 43 | |
f59a892f JR |
44 | /* |
45 | * Set lowest level to make sure all event levels are logged. | |
46 | * Any jar can override the default log4j rootLogger level | |
47 | * and a logger with no explicit level defaults to the non-null | |
48 | * parent level. Events could be ignored if the inherited value | |
49 | * is too low, thereby failing the test. | |
50 | * | |
51 | * See BSF -> https://issues.apache.org/jira/browse/BSF-24 | |
52 | */ | |
53 | lttng.setLevel(Level.ALL); | |
54 | lttng2.setLevel(Level.ALL); | |
55 | ||
504d4ace DG |
56 | int nrIter = Integer.parseInt(args[0]); |
57 | int waitTime = Integer.parseInt(args[1]); | |
58 | int fire_debug_tp = 0; | |
59 | int fire_second_tp = 0; | |
60 | ||
61 | if (args.length > 2) { | |
62 | fire_debug_tp = Integer.parseInt(args[2]); | |
63 | } | |
64 | if (args.length > 3) { | |
65 | fire_second_tp = Integer.parseInt(args[3]); | |
66 | } | |
67 | ||
0b7af945 | 68 | /* Start with the default Log4j configuration, which logs to console */ |
504d4ace | 69 | BasicConfigurator.configure(); |
0b7af945 MJ |
70 | |
71 | /* | |
72 | * Add a LTTng log appender to both loggers, which will also send the | |
73 | * logged events to UST. | |
74 | */ | |
75 | Appender lttngAppender = new LttngLogAppender(); | |
76 | lttng.addAppender(lttngAppender); | |
77 | lttng2.addAppender(lttngAppender); | |
504d4ace DG |
78 | |
79 | for (int iter = 0; iter < nrIter; iter++) { | |
80 | lttng.info("LOG4J tp fired!"); | |
81 | if (fire_debug_tp == 1) { | |
82 | /* Third arg, trigger debug TP. */ | |
83 | lttng.debug("LOG4J DEBUG tp fired"); | |
84 | } | |
85 | Thread.sleep(waitTime); | |
86 | } | |
87 | ||
88 | if (fire_second_tp == 1) { | |
89 | lttng2.info("LOG4J second logger fired"); | |
90 | } | |
0b7af945 MJ |
91 | |
92 | /* | |
93 | * Do not forget to close() all handlers so that the agent can shutdown | |
94 | * and the session daemon socket gets cleaned up explicitly. | |
95 | */ | |
96 | lttngAppender.close(); | |
504d4ace DG |
97 | } |
98 | } |