2 * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
3 * Copyright (C) 2014 David Goulet <dgoulet@efficios.com>
4 * Copyright (C) 2014 Christian Babeux <christian.babeux@efficios.com>
6 * SPDX-License-Identifier: GPL-2.0-only
10 import java
.io
.IOException
;
11 import java
.lang
.Integer
;
13 import org
.apache
.log4j
.Appender
;
14 import org
.apache
.log4j
.BasicConfigurator
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.apache
.log4j
.Level
;
17 import org
.lttng
.ust
.agent
.log4j
.LttngLogAppender
;
19 public class JTestLTTng
{
25 * Command-line arguments
27 * @throws InterruptedException
29 public static void main(String args
[]) throws IOException
, InterruptedException
{
31 Logger lttng
= Logger
.getLogger("log4j-event");
32 Logger lttng2
= Logger
.getLogger("log4j-event-2");
35 * Set lowest level to make sure all event levels are logged.
36 * Any jar can override the default log4j rootLogger level
37 * and a logger with no explicit level defaults to the non-null
38 * parent level. Events could be ignored if the inherited value
39 * is too low, thereby failing the test.
41 * See BSF -> https://issues.apache.org/jira/browse/BSF-24
43 lttng
.setLevel(Level
.ALL
);
44 lttng2
.setLevel(Level
.ALL
);
46 int nrIter
= Integer
.parseInt(args
[0]);
47 int waitTime
= Integer
.parseInt(args
[1]);
48 int fire_debug_tp
= 0;
49 int fire_second_tp
= 0;
51 if (args
.length
> 2) {
52 fire_debug_tp
= Integer
.parseInt(args
[2]);
54 if (args
.length
> 3) {
55 fire_second_tp
= Integer
.parseInt(args
[3]);
58 /* Start with the default Log4j configuration, which logs to console */
59 BasicConfigurator
.configure();
62 * Add a LTTng log appender to both loggers, which will also send the
63 * logged events to UST.
65 Appender lttngAppender
= new LttngLogAppender();
66 lttng
.addAppender(lttngAppender
);
67 lttng2
.addAppender(lttngAppender
);
69 for (int iter
= 0; iter
< nrIter
; iter
++) {
70 lttng
.info("LOG4J tp fired!");
71 if (fire_debug_tp
== 1) {
72 /* Third arg, trigger debug TP. */
73 lttng
.debug("LOG4J DEBUG tp fired");
75 Thread
.sleep(waitTime
);
78 if (fire_second_tp
== 1) {
79 lttng2
.info("LOG4J second logger fired");
83 * Do not forget to close() all handlers so that the agent can shutdown
84 * and the session daemon socket gets cleaned up explicitly.
86 lttngAppender
.close();
This page took 0.030529 seconds and 4 git commands to generate.