2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
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;
22 import java.util.logging.Handler;
23 import java.util.logging.LogManager;
24 import java.util.logging.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.runner.RunWith;
31 import org.junit.runners.Parameterized;
32 import org.lttng.tools.ILttngSession.Domain;
33 import org.lttng.ust.agent.jul.LttngLogHandler;
34 import org.lttng.ust.agent.utils.JulTestUtils;
37 * Implementation of {@link LoggerHierachyListITBase} for JUL log handlers.
39 * @author Alexandre Montplaisir
41 @RunWith(Parameterized.class)
42 public class JulLoggerHierarchyListIT extends LoggerHierachyListITBase {
44 private Logger parentLogger;
45 private Logger childLogger;
47 private Handler parentHandler;
48 private Handler childHandler;
53 * @param parentLoggerActive
54 * Parent logger has been instantiated
55 * @param parentLoggerHasHandler
56 * Parent logger has a LTTng handler attached to it
57 * @param childLoggerActive
58 * Child logger has been instantiated
59 * @param childLoggerHasHandler
60 * Child logger has a LTTng handler attached to it
62 public JulLoggerHierarchyListIT(boolean parentLoggerActive,
63 boolean parentLoggerHasHandler,
64 boolean childLoggerActive,
65 boolean childLoggerHasHandler) {
66 /* Set by parameters defined in the base class */
67 super(parentLoggerActive,
68 parentLoggerHasHandler,
70 childLoggerHasHandler);
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
81 public static void julClassSetup() {
82 JulTestUtils.testClassSetup();
89 public static void julClassCleanup() {
90 JulTestUtils.testClassCleanup();
96 @SuppressWarnings("static-method")
100 * Kind of hackish, but it's the only way to ensure that loggers are
101 * really removed in-between tests, since LogManager does not provide a
102 * way to forcibly remove a logger, and it doesn't seem like it will any
103 * time soon, see http://bugs.java.com/view_bug.do?bug_id=4811930
105 LogManager.getLogManager().reset();
113 public void cleanup() {
114 if (parentLogger != null) {
115 if (parentHandler != null) {
116 parentLogger.removeHandler(parentHandler);
117 parentHandler.close();
118 parentHandler = null;
123 if (childLogger != null) {
124 if (childHandler != null) {
125 childLogger.removeHandler(childHandler);
126 childHandler.close();
132 LogManager.getLogManager().reset();
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 protected Domain getDomain() {
146 protected void activateLoggers() throws IOException {
147 if (parentLoggerActive) {
148 parentLogger = Logger.getLogger(PARENT_LOGGER);
149 if (parentLoggerHasHandler) {
150 parentHandler = new LttngLogHandler();
151 parentLogger.addHandler(parentHandler);
155 if (childLoggerActive) {
156 childLogger = Logger.getLogger(CHILD_LOGGER);
157 if (childLoggerHasHandler) {
158 childHandler = new LttngLogHandler();
159 childLogger.addHandler(childHandler);