Tests: Preemptively fail infinite blocking tests when low on disk space
[lttng-tools.git] / tests / regression / ust / java-log4j / JTestLTTngLog4j.java
CommitLineData
504d4ace 1/*
9d16b343
MJ
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>
504d4ace 5 *
9d16b343 6 * SPDX-License-Identifier: GPL-2.0-only
504d4ace 7 *
504d4ace
DG
8 */
9
10import java.io.IOException;
11import java.lang.Integer;
12
0b7af945 13import org.apache.log4j.Appender;
504d4ace 14import org.apache.log4j.BasicConfigurator;
0b7af945 15import org.apache.log4j.Logger;
f59a892f 16import org.apache.log4j.Level;
0b7af945 17import org.lttng.ust.agent.log4j.LttngLogAppender;
504d4ace 18
c0554459 19public class JTestLTTngLog4j {
504d4ace 20
0b7af945
MJ
21 /**
22 * Application start
23 *
24 * @param args
25 * Command-line arguments
26 * @throws IOException
27 * @throws InterruptedException
28 */
29 public static void main(String args[]) throws IOException, InterruptedException {
504d4ace 30
504d4ace
DG
31 Logger lttng = Logger.getLogger("log4j-event");
32 Logger lttng2 = Logger.getLogger("log4j-event-2");
0b7af945 33
f59a892f
JR
34 /*
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.
40 *
41 * See BSF -> https://issues.apache.org/jira/browse/BSF-24
42 */
43 lttng.setLevel(Level.ALL);
44 lttng2.setLevel(Level.ALL);
45
504d4ace
DG
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;
50
51 if (args.length > 2) {
52 fire_debug_tp = Integer.parseInt(args[2]);
53 }
54 if (args.length > 3) {
55 fire_second_tp = Integer.parseInt(args[3]);
56 }
57
0b7af945 58 /* Start with the default Log4j configuration, which logs to console */
504d4ace 59 BasicConfigurator.configure();
0b7af945
MJ
60
61 /*
62 * Add a LTTng log appender to both loggers, which will also send the
63 * logged events to UST.
64 */
65 Appender lttngAppender = new LttngLogAppender();
66 lttng.addAppender(lttngAppender);
67 lttng2.addAppender(lttngAppender);
504d4ace
DG
68
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");
74 }
75 Thread.sleep(waitTime);
76 }
77
78 if (fire_second_tp == 1) {
79 lttng2.info("LOG4J second logger fired");
80 }
0b7af945
MJ
81
82 /*
83 * Do not forget to close() all handlers so that the agent can shutdown
84 * and the session daemon socket gets cleaned up explicitly.
85 */
86 lttngAppender.close();
504d4ace
DG
87 }
88}
This page took 0.05746 seconds and 4 git commands to generate.