2 * Copyright (C) 2022, EfficiOS Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 package org
.lttng
.ust
.agent
.integration
.events
;
21 import java
.io
.IOException
;
24 import org
.apache
.logging
.log4j
.core
.Appender
;
25 import org
.apache
.logging
.log4j
.core
.Logger
;
26 import org
.junit
.After
;
27 import org
.junit
.AfterClass
;
28 import org
.junit
.Before
;
29 import org
.junit
.BeforeClass
;
30 import org
.junit
.Test
;
31 import org
.lttng
.tools
.ILttngSession
.Domain
;
32 import org
.lttng
.ust
.agent
.ILttngHandler
;
33 import org
.lttng
.ust
.agent
.log4j2
.LttngLogAppender
;
34 import org
.lttng
.ust
.agent
.utils
.Log4j2TestContext
;
35 import org
.lttng
.ust
.agent
.utils
.Log4j2TestUtils
;
38 * Enabled events test for the LTTng-UST Log4j log handler.
40 public class Log4j2EnabledEventsIT
extends EnabledEventsITBase
{
42 private static final String APPENDER_NAME_A
= "LttngA";
43 private static final String APPENDER_NAME_B
= "LttngB";
44 private static final String APPENDER_NAME_C
= "LttngC";
46 private static final Domain DOMAIN
= Domain
.LOG4J
;
48 private Log4j2TestContext testContext
;
50 private Logger loggerA
;
51 private Logger loggerB
;
52 private Logger loggerC
;
53 private Logger loggerD
;
59 public static void log4j2ClassSetup() {
60 Log4j2TestUtils
.testClassSetup();
67 public static void log4j2ClassCleanup() {
68 Log4j2TestUtils
.testClassCleanup();
74 * @throws SecurityException
77 @SuppressWarnings("resource")
79 public void log4j2Setup() throws SecurityException
, IOException
{
81 testContext
= new Log4j2TestContext("log4j2.Log4j2EnabledEventsIT.xml");
83 testContext
.beforeTest();
85 loggerA
= testContext
.getLoggerContext().getLogger(EVENT_NAME_A
);
86 loggerB
= testContext
.getLoggerContext().getLogger(EVENT_NAME_B
);
87 loggerC
= testContext
.getLoggerContext().getLogger(EVENT_NAME_C
);
88 loggerD
= testContext
.getLoggerContext().getLogger(EVENT_NAME_D
);
90 handlerA
= (ILttngHandler
) loggerA
.getAppenders().get(APPENDER_NAME_A
);
91 handlerB
= (ILttngHandler
) loggerB
.getAppenders().get(APPENDER_NAME_B
);
92 handlerC
= (ILttngHandler
) loggerC
.getAppenders().get(APPENDER_NAME_C
);
99 public void log4j2Teardown() {
105 testContext
.afterTest();
109 protected Domain
getDomain() {
114 protected boolean closeHandlers()
120 protected void sendEventsToLoggers() {
121 Log4j2TestUtils
.send10Events(loggerA
);
122 Log4j2TestUtils
.send10Events(loggerB
);
123 Log4j2TestUtils
.send10Events(loggerC
);
124 Log4j2TestUtils
.send10Events(loggerD
);
128 protected void sendLocalizedEvent(String rawString
, Object
[] params
) {
129 throw new UnsupportedOperationException();
134 public void testLocalizedMessage() {
135 /* Does not apply to log4j 1.2.x */