diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java index 630976ad64d..6556a491a8a 100644 --- a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java +++ b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactory.java @@ -35,7 +35,7 @@ import javax.management.ReflectionException; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; -public class JettyLoggerFactory implements ILoggerFactory, DynamicMBean, JettyLoggerFactoryMBean +public class JettyLoggerFactory implements ILoggerFactory, DynamicMBean { private final JettyLoggerConfiguration configuration; private final JettyLogger rootLogger; @@ -254,11 +254,6 @@ public class JettyLoggerFactory implements ILoggerFactory, DynamicMBean, JettyLo return ret; } - /* - setLoggerLevel(String loggerName, String levelName); - String getLoggerLevel(String loggerName); - */ - @Override public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException { diff --git a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactoryMBean.java b/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactoryMBean.java deleted file mode 100644 index 6e9bab31fbb..00000000000 --- a/jetty-slf4j-impl/src/main/java/org/eclipse/jetty/logging/JettyLoggerFactoryMBean.java +++ /dev/null @@ -1,25 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.logging; - -public interface JettyLoggerFactoryMBean -{ - int getLoggerCount(); - - String[] getLoggerNames(); - - boolean setLoggerLevel(String loggerName, String levelName); - - String getLoggerLevel(String loggerName); -} diff --git a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JMXTest.java b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JMXTest.java index ffc29298adb..921beb59e55 100644 --- a/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JMXTest.java +++ b/jetty-slf4j-impl/src/test/java/org/eclipse/jetty/logging/JMXTest.java @@ -19,7 +19,6 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.stream.Stream; -import javax.management.JMX; import javax.management.MBeanAttributeInfo; import javax.management.MBeanInfo; import javax.management.MBeanServer; @@ -52,28 +51,44 @@ public class JMXTest MBeanAttributeInfo attr = Stream.of(attributeInfos).filter((a) -> a.getName().equals("LoggerNames")).findFirst().orElseThrow(); assertThat("attr", attr.getDescription(), is("List of Registered Loggers by Name.")); - JettyLoggerFactoryMBean mbean = JMX.newMBeanProxy(mbeanServer, objectName, JettyLoggerFactoryMBean.class); + // Do some MBean attribute testing + int loggerCount; // Only the root logger. - assertEquals(1, mbean.getLoggerCount()); + loggerCount = (int)mbeanServer.getAttribute(objectName, "LoggerCount"); + assertEquals(1, loggerCount); JettyLoggerFactory loggerFactory = (JettyLoggerFactory)LoggerFactory.getILoggerFactory(); JettyLogger child = loggerFactory.getJettyLogger("org.eclipse.jetty.logging"); JettyLogger parent = loggerFactory.getJettyLogger("org.eclipse.jetty"); - assertEquals(3, mbean.getLoggerCount()); + loggerCount = (int)mbeanServer.getAttribute(objectName, "LoggerCount"); + assertEquals(3, loggerCount); - // Names are sorted. + // Names from JMX are sorted, so lets sort our expected list too. List expected = new ArrayList<>(Arrays.asList(JettyLogger.ROOT_LOGGER_NAME, parent.getName(), child.getName())); expected.sort(String::compareTo); - String[] loggerNames = mbean.getLoggerNames(); + String[] loggerNames = (String[])mbeanServer.getAttribute(objectName, "LoggerNames"); assertEquals(expected, Arrays.asList(loggerNames)); + // Do some MBean invoker testing + String operationName; + String[] signature; + Object[] params; + // Setting the parent level should propagate to the children. parent.setLevel(JettyLevel.DEBUG); - assertEquals(parent.getLevel().toString(), mbean.getLoggerLevel(child.getName())); + operationName = "getLoggerName"; + signature = new String[]{String.class.getName()}; + params = new Object[]{child.getName()}; + String levelName = (String)mbeanServer.invoke(objectName, operationName, params, signature); + assertEquals(parent.getLevel().toString(), levelName); // Setting the level via JMX affects the logger. - assertTrue(mbean.setLoggerLevel(child.getName(), "INFO")); + operationName = "setLoggerName"; + signature = new String[]{String.class.getName(), String.class.getName()}; + params = new Object[]{child.getName(), "INFO"}; + boolean result = (boolean)mbeanServer.invoke(objectName, operationName, params, signature); + assertTrue(result); assertEquals(JettyLevel.INFO, child.getLevel()); } }