This is an automated email from the ASF dual-hosted git repository. robbie pushed a commit to branch new-logging in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit de19847863b444a791b7dd7f8a713c310346bb46 Author: Robbie Gemmell <[email protected]> AuthorDate: Mon May 23 17:04:23 2022 +0100 remove log config reloader that depends on jboss logmanager --- .../server/LoggingConfigurationFileReloader.java | 89 ---- .../core/server/LoggingConfigurationUpdater.java | 447 --------------------- .../core/server/impl/ActiveMQServerImpl.java | 10 - .../LoggingConfigurationFileReloaderTest.java | 130 ------ .../src/test/resources/reload-logging-1.properties | 21 - .../src/test/resources/reload-logging-2.properties | 21 - 6 files changed, 718 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationFileReloader.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationFileReloader.java deleted file mode 100644 index b96c24cb6e..0000000000 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationFileReloader.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.activemq.artemis.core.server; - -import java.io.InputStream; -import java.net.URL; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.activemq.artemis.core.server.reload.ReloadCallback; -import org.jboss.logmanager.Configurator; -import org.jboss.logmanager.LogContext; -import org.jboss.logmanager.PropertyConfigurator; -import org.jboss.logmanager.config.LogContextConfiguration; - -public class LoggingConfigurationFileReloader implements ReloadCallback { - - private final Lock lock = new ReentrantLock(); - private final org.jboss.logmanager.Logger.AttachmentKey<LoggingConfigurationUpdater> KEY = new org.jboss.logmanager.Logger.AttachmentKey<>(); - - @Override - public void reload(URL uri) throws Exception { - ActiveMQServerLogger.LOGGER.reloadingConfiguration("logging"); - final LoggingConfigurationUpdater updater = getOrCreateUpdater(); - if (updater == null) { - ActiveMQServerLogger.LOGGER.loggingReloadFailed(uri.toString(), null); - return; - } - try (InputStream in = uri.openStream()) { - lock.lock(); - updater.configure(in); - } catch (Exception e) { - ActiveMQServerLogger.LOGGER.loggingReloadFailed(uri.toString(), e); - } finally { - lock.unlock(); - } - } - - private LoggingConfigurationUpdater getOrCreateUpdater() { - final LogContext logContext = LogContext.getLogContext(); - final org.jboss.logmanager.Logger rootLogger = logContext.getLogger(""); - LoggingConfigurationUpdater updater = rootLogger.getAttachment(KEY); - if (updater == null) { - final LogContextConfiguration logContextConfiguration = getOrCreateConfiguration(rootLogger); - if (logContextConfiguration == null) { - return null; - } - updater = new LoggingConfigurationUpdater(logContextConfiguration); - final LoggingConfigurationUpdater appearing = rootLogger.attachIfAbsent(KEY, updater); - if (appearing != null) { - updater = appearing; - } - } - return updater; - } - - private LogContextConfiguration getOrCreateConfiguration(final org.jboss.logmanager.Logger rootLogger) { - Configurator configurator = rootLogger.getAttachment(Configurator.ATTACHMENT_KEY); - if (configurator == null) { - configurator = new PropertyConfigurator(rootLogger.getLogContext()); - final Configurator appearing = rootLogger.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator); - if (appearing != null) { - configurator = appearing; - } - } - if (configurator instanceof PropertyConfigurator) { - return ((PropertyConfigurator) configurator).getLogContextConfiguration(); - } - if (configurator instanceof LogContextConfiguration) { - return (LogContextConfiguration) configurator; - } - return null; - } -} \ No newline at end of file diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationUpdater.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationUpdater.java deleted file mode 100644 index f8be8e967d..0000000000 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/LoggingConfigurationUpdater.java +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.activemq.artemis.core.server; - -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.Properties; -import java.util.regex.Pattern; - -import org.jboss.logmanager.config.ErrorManagerConfiguration; -import org.jboss.logmanager.config.FilterConfiguration; -import org.jboss.logmanager.config.FormatterConfiguration; -import org.jboss.logmanager.config.HandlerConfiguration; -import org.jboss.logmanager.config.HandlerContainingConfigurable; -import org.jboss.logmanager.config.LogContextConfiguration; -import org.jboss.logmanager.config.LoggerConfiguration; -import org.jboss.logmanager.config.PojoConfiguration; -import org.jboss.logmanager.config.PropertyConfigurable; -import org.jboss.logmanager.config.ValueExpression; - -public class LoggingConfigurationUpdater { - - private static final String[] EMPTY_STRINGS = new String[0]; - private static final Pattern EXPRESSION_PATTERN = Pattern.compile(".*\\$\\{.*\\}.*"); - private static final String LOGGERS = "loggers"; - private static final String HANDLERS = "handlers"; - private static final String FILTERS = "filters"; - private static final String FORMATTERS = "formatters"; - private static final String ERROR_MANAGERS = "errorManagers"; - private static final String POJOS = "pojos"; - private static final String LOGGER = "logger"; - private static final String LEVEL = "level"; - private static final String HANDLER = "handler"; - private static final String FORMATTER = "formatter"; - private static final String ENCODING = "encoding"; - private static final String ERROR_MANAGER = "errorManager"; - private static final String POST_CONFIGURATION = "postConfiguration"; - private static final String POJO = "pojo"; - private static final String MODULE = "module"; - private static final String PROPERTIES = "properties"; - private static final String FILTER = "filter"; - private static final String CONSTRUCTOR_PROPERTIES = "constructorProperties"; - private static final String USE_PARENT_HANDLERS = "useParentHandlers"; - - private final LogContextConfiguration config; - - public LoggingConfigurationUpdater(final LogContextConfiguration config) { - this.config = config; - } - - /** - * {@inheritDoc} - */ - public void configure(final InputStream inputStream) throws IOException { - final Properties properties = new Properties(); - try { - properties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - inputStream.close(); - } finally { - safeClose(inputStream); - } - configure(properties); - } - - /** - * Configure the log manager from the given properties. - * <p/> - * The following values read in from a configuration will be trimmed of prefixed and trailing whitespace: - * <pre> - * <ul> - * <li>logger.NAME.filter</li> - * <li>logger.NAME.level</li> - * <li>logger.NAME.useParentHandlers</li> - * <li>handler.NAME.filter</li> - * <li>handler.NAME.formatter</li> - * <li>handler.NAME.level</li> - * <li>handler.NAME.encoding</li> - * <li>handler.NAME.errorManager</li> - * </ul> - * </pre> - * - * @param properties the properties - */ - private void configure(final Properties properties) { - try { - final Collection<String> handlersToRemove = config.getHandlerNames(); - // Start with the list of loggers to configure. The root logger is always on the list. - handlersToRemove.removeAll(configureLogger(properties, "")); - - // And, for each logger name, configure any filters, handlers, etc. - final String[] loggerNames = getStringCsvArray(properties, LOGGERS); - for (String loggerName : loggerNames) { - handlersToRemove.removeAll(configureLogger(properties, loggerName)); - } - // Remove any loggers that are not longer required - final Collection<String> loggersToRemove = config.getLoggerNames(); - loggersToRemove.remove(""); - loggersToRemove.removeAll(Arrays.asList(loggerNames)); - for (String loggerName : loggersToRemove) { - config.removeLoggerConfiguration(loggerName); - } - - // Configure any declared handlers. - final String[] handlerNames = getStringCsvArray(properties, HANDLERS); - for (String handlerName : handlerNames) { - configureHandler(properties, handlerName); - } - // Remove any handlers that are not longer required - handlersToRemove.removeAll(Arrays.asList(handlerNames)); - for (String handlerName : handlersToRemove) { - config.removeHandlerConfiguration(handlerName); - } - - // Configure any declared filters. - for (String filterName : getStringCsvArray(properties, FILTERS)) { - configureFilter(properties, filterName); - } - - // Configure any declared formatters. - for (String formatterName : getStringCsvArray(properties, FORMATTERS)) { - configureFormatter(properties, formatterName); - } - - // Configure any declared error managers. - for (String errorManagerName : getStringCsvArray(properties, ERROR_MANAGERS)) { - configureErrorManager(properties, errorManagerName); - } - - // Configure POJOs - for (String pojoName : getStringCsvArray(properties, POJOS)) { - configurePojos(properties, pojoName); - } - config.commit(); - } finally { - config.forget(); - } - } - - private List<String> configureLogger(final Properties properties, final String loggerName) { - final LoggerConfiguration loggerConfiguration; - if (config.getLoggerNames().contains(loggerName)) { - loggerConfiguration = config.getLoggerConfiguration(loggerName); - } else { - loggerConfiguration = config.addLoggerConfiguration(loggerName); - } - - // Get logger level - final String levelName = getStringProperty(properties, getKey(LOGGER, loggerName, LEVEL)); - if (notEqual(levelName, loggerConfiguration.getLevelValueExpression())) { - loggerConfiguration.setLevel(levelName == null ? "ALL" : levelName); - } - - // Get logger filter - final String filterName = getStringProperty(properties, getKey(LOGGER, loggerName, FILTER)); - final ValueExpression<String> newValue = ValueExpression.STRING_RESOLVER.resolve(filterName); - if (notEqual(newValue, loggerConfiguration.getFilterValueExpression())) { - loggerConfiguration.setFilter(filterName); - final String resolvedFilter = loggerConfiguration.getFilterValueExpression().getResolvedValue(); - if (resolvedFilter != null) { - // Check for a filter class - final String filterClassName = getStringProperty(properties, getKey(FILTER, resolvedFilter)); - // If the filter class is null, assume it's a filter expression - if (filterClassName != null) { - configureFilter(properties, resolvedFilter); - } - } - } - - // Get logger handlers - configureHandlerNames(properties, loggerConfiguration, LOGGER, loggerName); - - // Get logger properties - final String useParentHandlersString = getStringProperty(properties, getKey(LOGGER, loggerName, USE_PARENT_HANDLERS)); - if (booleanNotEqual(useParentHandlersString, loggerConfiguration.getUseParentHandlersValueExpression())) { - // Check for expression - if (EXPRESSION_PATTERN.matcher(useParentHandlersString).matches()) { - loggerConfiguration.setUseParentHandlers(useParentHandlersString); - } else { - loggerConfiguration.setUseParentHandlers(Boolean.parseBoolean(useParentHandlersString)); - } - } - return loggerConfiguration.getHandlerNames(); - } - - private void configureFilter(final Properties properties, final String filterName) { - final String className = getStringProperty(properties, getKey(FILTER, filterName)); - if (className == null) { - // Assume we're using a filter expression - return; - } - final FilterConfiguration configuration; - if (config.getFilterNames().contains(filterName)) { - configuration = config.getFilterConfiguration(filterName); - } else { - configuration = config.addFilterConfiguration(getStringProperty(properties, getKey(FILTER, filterName, MODULE)), className, filterName, getStringCsvArray(properties, getKey(FILTER, filterName, CONSTRUCTOR_PROPERTIES))); - } - final String[] postConfigurationMethods = getStringCsvArray(properties, getKey(FILTER, filterName, POST_CONFIGURATION)); - configuration.setPostConfigurationMethods(postConfigurationMethods); - configureProperties(properties, configuration, getKey(FILTER, filterName)); - } - - private boolean configureFormatter(final Properties properties, final String formatterName) { - final String className = getStringProperty(properties, getKey(FORMATTER, formatterName)); - if (className == null) { - printError("Formatter %s is not defined%n", formatterName); - return false; - } - final FormatterConfiguration configuration; - if (config.getFormatterNames().contains(formatterName)) { - configuration = config.getFormatterConfiguration(formatterName); - } else { - configuration = config.addFormatterConfiguration(getStringProperty(properties, getKey(FORMATTER, formatterName, MODULE)), className, formatterName, getStringCsvArray(properties, getKey(FORMATTER, formatterName, CONSTRUCTOR_PROPERTIES))); - } - final String[] postConfigurationMethods = getStringCsvArray(properties, getKey(FORMATTER, formatterName, POST_CONFIGURATION)); - configuration.setPostConfigurationMethods(postConfigurationMethods); - configureProperties(properties, configuration, getKey(FORMATTER, formatterName)); - return true; - } - - private boolean configureErrorManager(final Properties properties, final String errorManagerName) { - final String className = getStringProperty(properties, getKey(ERROR_MANAGER, errorManagerName)); - if (className == null) { - printError("Error manager %s is not defined%n", errorManagerName); - return false; - } - final ErrorManagerConfiguration configuration; - if (config.getErrorManagerNames().contains(errorManagerName)) { - configuration = config.getErrorManagerConfiguration(errorManagerName); - } else { - configuration = config.addErrorManagerConfiguration(getStringProperty(properties, getKey(ERROR_MANAGER, errorManagerName, MODULE)), className, errorManagerName, getStringCsvArray(properties, getKey(ERROR_MANAGER, errorManagerName, CONSTRUCTOR_PROPERTIES))); - } - final String[] postConfigurationMethods = getStringCsvArray(properties, getKey(ERROR_MANAGER, errorManagerName, POST_CONFIGURATION)); - configuration.setPostConfigurationMethods(postConfigurationMethods); - configureProperties(properties, configuration, getKey(ERROR_MANAGER, errorManagerName)); - return true; - } - - private boolean configureHandler(final Properties properties, final String handlerName) { - final String className = getStringProperty(properties, getKey(HANDLER, handlerName)); - if (className == null) { - printError("Handler %s is not defined%n", handlerName); - return false; - } - final HandlerConfiguration configuration; - if (config.getHandlerNames().contains(handlerName)) { - configuration = config.getHandlerConfiguration(handlerName); - } else { - configuration = config.addHandlerConfiguration(getStringProperty(properties, getKey(HANDLER, handlerName, MODULE)), className, handlerName, getStringCsvArray(properties, getKey(HANDLER, handlerName, CONSTRUCTOR_PROPERTIES))); - } - final String filter = getStringProperty(properties, getKey(HANDLER, handlerName, FILTER)); - if (notEqual(filter, configuration.getFilterValueExpression())) { - configuration.setFilter(filter); - final String resolvedFilter = configuration.getFilterValueExpression().getResolvedValue(); - if (resolvedFilter != null) { - // Check for a filter class - final String filterClassName = getStringProperty(properties, getKey(FILTER, resolvedFilter)); - // If the filter class is null, assume it's a filter expression - if (filterClassName != null) { - configureFilter(properties, resolvedFilter); - } - } - } - final String levelName = getStringProperty(properties, getKey(HANDLER, handlerName, LEVEL)); - if (notEqual(levelName, configuration.getLevelValueExpression())) { - configuration.setLevel(levelName == null ? "ALL" : levelName); - } - final String formatterName = getStringProperty(properties, getKey(HANDLER, handlerName, FORMATTER)); - if (formatterName != null) { - if (getStringProperty(properties, getKey(FORMATTER, ValueExpression.STRING_RESOLVER.resolve(formatterName).getResolvedValue())) == null) { - printError("Formatter %s is not defined%n", formatterName); - } else { - final ValueExpression<String> newValue = ValueExpression.STRING_RESOLVER.resolve(formatterName); - if (notEqual(newValue, configuration.getFormatterNameValueExpression())) { - if (configureFormatter(properties, newValue.getResolvedValue())) { - configuration.setFormatterName(formatterName); - } - } - } - } - final String encoding = getStringProperty(properties, getKey(HANDLER, handlerName, ENCODING)); - if (notEqual(encoding, configuration.getEncodingValueExpression())) { - configuration.setEncoding(encoding); - } - final String errorManagerName = getStringProperty(properties, getKey(HANDLER, handlerName, ERROR_MANAGER)); - if (errorManagerName != null) { - if (getStringProperty(properties, getKey(ERROR_MANAGER, ValueExpression.STRING_RESOLVER.resolve(errorManagerName).getResolvedValue())) == null) { - printError("Error manager %s is not defined%n", errorManagerName); - } else { - final ValueExpression<String> newValue = ValueExpression.STRING_RESOLVER.resolve(errorManagerName); - if (notEqual(newValue, configuration.getErrorManagerNameValueExpression())) { - if (configureErrorManager(properties, newValue.getResolvedValue())) { - configuration.setErrorManagerName(errorManagerName); - } - } - } - } - configureHandlerNames(properties, configuration, HANDLER, handlerName); - final String[] postConfigurationMethods = getStringCsvArray(properties, getKey(HANDLER, handlerName, POST_CONFIGURATION)); - configuration.setPostConfigurationMethods(postConfigurationMethods); - configureProperties(properties, configuration, getKey(HANDLER, handlerName)); - return true; - } - - private void configurePojos(final Properties properties, final String pojoName) { - final String className = getStringProperty(properties, getKey(POJO, pojoName)); - if (className == null) { - printError("POJO %s is not defined%n", pojoName); - return; - } - final PojoConfiguration configuration; - if (config.getPojoNames().contains(pojoName)) { - configuration = config.getPojoConfiguration(pojoName); - } else { - configuration = config.addPojoConfiguration(getStringProperty(properties, getKey(POJO, pojoName, MODULE)), getStringProperty(properties, getKey(POJO, pojoName)), pojoName, getStringCsvArray(properties, getKey(POJO, pojoName, CONSTRUCTOR_PROPERTIES))); - } - final String[] postConfigurationMethods = getStringCsvArray(properties, getKey(POJO, pojoName, POST_CONFIGURATION)); - configuration.setPostConfigurationMethods(postConfigurationMethods); - configureProperties(properties, configuration, getKey(POJO, pojoName)); - } - - private void configureProperties(final Properties properties, - final PropertyConfigurable configurable, - final String prefix) { - final List<String> propertyNames = getStringCsvList(properties, getKey(prefix, PROPERTIES)); - for (String propertyName : propertyNames) { - final String valueString = getStringProperty(properties, getKey(prefix, propertyName), false); - if (notEqual(valueString, configurable.getPropertyValueExpression(propertyName))) { - configurable.setPropertyValueString(propertyName, valueString); - } - } - } - - private void configureHandlerNames(final Properties properties, - final HandlerContainingConfigurable configuration, - final String prefix, - final String name) { - final String[] handlerNames = getStringCsvArray(properties, getKey(prefix, name, HANDLERS)); - final Collection<String> availableHandlers = new ArrayList<>(); - for (String handlerName : handlerNames) { - if (configureHandler(properties, handlerName)) { - availableHandlers.add(handlerName); - } - } - configuration.setHandlerNames(availableHandlers); - } - - private static String getKey(final String prefix, final String objectName) { - return objectName.length() > 0 ? prefix + "." + objectName : prefix; - } - - private static String getKey(final String prefix, final String objectName, final String key) { - return objectName.length() > 0 ? prefix + "." + objectName + "." + key : prefix + "." + key; - } - - private static String getStringProperty(final Properties properties, final String key) { - return getStringProperty(properties, key, true); - } - - private static String getStringProperty(final Properties properties, final String key, final boolean trim) { - final String value = properties.getProperty(key); - return (trim ? (value == null ? null : value.trim()) : value); - } - - private static String[] getStringCsvArray(final Properties properties, final String key) { - final String property = properties.getProperty(key, ""); - if (property == null) { - return EMPTY_STRINGS; - } - final String value = property.trim(); - if (value.length() == 0) { - return EMPTY_STRINGS; - } - return value.split("\\s*,\\s*"); - } - - private static List<String> getStringCsvList(final Properties properties, final String key) { - return new ArrayList<>(Arrays.asList(getStringCsvArray(properties, key))); - } - - private static void printError(final String format, final Object... args) { - System.err.printf(format, args); - } - - private static void safeClose(final Closeable stream) { - if (stream != null) - try { - stream.close(); - } catch (Exception e) { - // can't do anything about it - } - } - - private static boolean notEqual(final ValueExpression<String> newValue, final ValueExpression<String> currentValue) { - if (newValue == null) { - return currentValue.getResolvedValue() != null; - } - return !Objects.equals(newValue.getValue(), currentValue.getValue()); - } - - private static boolean notEqual(final String newValue, final ValueExpression<String> currentValue) { - if (newValue == null) { - return currentValue.getResolvedValue() != null; - } - if (currentValue.isExpression()) { - final String resolvedCurrentValue = currentValue.getResolvedValue(); - final String resolvedNewValue = ValueExpression.STRING_RESOLVER.resolve(newValue).getResolvedValue(); - return resolvedCurrentValue == null ? resolvedNewValue != null : !resolvedCurrentValue.equals(resolvedNewValue); - } - return !newValue.equals(currentValue.getValue()); - } - - private static boolean booleanNotEqual(final String newValue, final ValueExpression<Boolean> currentValue) { - if (newValue == null) { - return currentValue.getResolvedValue() != null; - } - if (currentValue.isExpression()) { - final Boolean resolvedCurrentValue = currentValue.getResolvedValue(); - final Boolean resolvedNewValue = ValueExpression.BOOLEAN_RESOLVER.resolve(newValue).getResolvedValue(); - return resolvedCurrentValue == null ? resolvedNewValue != null : !resolvedCurrentValue.equals(resolvedNewValue); - } - return !newValue.equals(currentValue.getValue()); - } - -} \ No newline at end of file diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index e3c19eb576..5efe59bba4 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -128,7 +128,6 @@ import org.apache.activemq.artemis.core.server.BrokerConnection; import org.apache.activemq.artemis.core.server.Divert; import org.apache.activemq.artemis.core.server.JournalType; import org.apache.activemq.artemis.core.server.LargeServerMessage; -import org.apache.activemq.artemis.core.server.LoggingConfigurationFileReloader; import org.apache.activemq.artemis.core.server.MemoryManager; import org.apache.activemq.artemis.core.server.MessageReference; import org.apache.activemq.artemis.core.server.NetworkHealthCheck; @@ -3209,15 +3208,6 @@ public class ActiveMQServerImpl implements ActiveMQServer { if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) { reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri)); } - - if (System.getProperty("logging.configuration") != null) { - try { - reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader()); - } catch (Exception e) { - // a syntax error with the logging system property shouldn't prevent the server from starting - ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e); - } - } } if (hasBrokerPlugins()) { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/reload/LoggingConfigurationFileReloaderTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/reload/LoggingConfigurationFileReloaderTest.java deleted file mode 100644 index 9ddab44935..0000000000 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/reload/LoggingConfigurationFileReloaderTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.activemq.artemis.core.reload; - -import java.util.logging.LogManager; - -import org.apache.activemq.artemis.core.server.LoggingConfigurationFileReloader; -import org.apache.activemq.artemis.utils.ClassloadingUtil; -import org.apache.activemq.artemis.utils.SpawnedVMSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -//TODO: This is testing JBoss Logging reloading via LoggingConfigurationFileReloader, it should be updated or removed if using something else -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class LoggingConfigurationFileReloaderTest { - - private static final LogManager logManager = LogManager.getLogManager(); - private static final Logger root = LoggerFactory.getLogger(""); - private static final Logger test1 = LoggerFactory.getLogger("test1"); - private static final Logger test2 = LoggerFactory.getLogger("test2"); - private static final Logger test3 = LoggerFactory.getLogger("test3"); - - public static void main(String[] args) { - try { - LoggingConfigurationFileReloaderTest test = new LoggingConfigurationFileReloaderTest(); - test.doTestA(); - System.exit(0); - } catch (Throwable e) { - System.exit(1); - } - } - - @Test - public void testA() throws Exception { - Process p = SpawnedVMSupport.spawnVM(LoggingConfigurationFileReloaderTest.class.getName()); - Assert.assertEquals(0, p.waitFor()); - } - - public void doTestA() throws Exception { - - /** This is making sure we won't mess with the configuration for other tests */ - validateInitialLoggers(); - - LoggingConfigurationFileReloader loggingConfigurationFileReloader = new LoggingConfigurationFileReloader(); - loggingConfigurationFileReloader.reload(ClassloadingUtil.findResource("reload-logging-1.properties")); - - assertTrue(root.isErrorEnabled()); - assertTrue(root.isWarnEnabled()); - assertFalse(root.isInfoEnabled()); - assertFalse(root.isDebugEnabled()); - assertFalse(root.isTraceEnabled()); - - assertTrue(test1.isErrorEnabled()); - assertTrue(test1.isWarnEnabled()); - assertTrue(test1.isInfoEnabled()); - assertTrue(test1.isDebugEnabled()); - assertTrue(test1.isTraceEnabled()); - - assertTrue(test2.isErrorEnabled()); - assertFalse(test2.isWarnEnabled()); - assertFalse(test2.isInfoEnabled()); - assertFalse(test2.isDebugEnabled()); - assertFalse(test2.isTraceEnabled()); - - loggingConfigurationFileReloader.reload(ClassloadingUtil.findResource("reload-logging-2.properties")); - - assertTrue(root.isErrorEnabled()); - assertFalse(root.isWarnEnabled()); - assertFalse(root.isInfoEnabled()); - assertFalse(root.isDebugEnabled()); - assertFalse(root.isTraceEnabled()); - - assertTrue(test1.isErrorEnabled()); - assertTrue(test1.isWarnEnabled()); - assertFalse(test1.isInfoEnabled()); - assertFalse(test1.isDebugEnabled()); - assertFalse(test1.isTraceEnabled()); - - assertTrue(test3.isErrorEnabled()); - assertTrue(test3.isWarnEnabled()); - assertTrue(test3.isInfoEnabled()); - assertTrue(test3.isDebugEnabled()); - assertFalse(test3.isTraceEnabled()); - } - - @Test - public void testB() { - validateInitialLoggers(); - } - - public void validateInitialLoggers() { - // everything defaults to INFO - assertTrue(root.isErrorEnabled()); - assertTrue(root.isWarnEnabled()); - assertFalse(root.isDebugEnabled()); - assertFalse(root.isTraceEnabled()); - - assertTrue(test1.isErrorEnabled()); - assertTrue(test1.isWarnEnabled()); - assertFalse(test1.isDebugEnabled()); - assertFalse(test1.isTraceEnabled()); - - assertTrue(test2.isErrorEnabled()); - assertTrue(test2.isWarnEnabled()); - assertFalse(test2.isDebugEnabled()); - assertFalse(test2.isTraceEnabled()); - } -} \ No newline at end of file diff --git a/artemis-server/src/test/resources/reload-logging-1.properties b/artemis-server/src/test/resources/reload-logging-1.properties deleted file mode 100644 index 7aba821f29..0000000000 --- a/artemis-server/src/test/resources/reload-logging-1.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -loggers=test1,test2 -logger.test1.level=TRACE -logger.test2.level=ERROR -logger.level=WARN \ No newline at end of file diff --git a/artemis-server/src/test/resources/reload-logging-2.properties b/artemis-server/src/test/resources/reload-logging-2.properties deleted file mode 100644 index 8ff0a5f07b..0000000000 --- a/artemis-server/src/test/resources/reload-logging-2.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -loggers=test1,test3 -logger.test1.level=WARN -logger.test3.level=DEBUG -logger.level=ERROR \ No newline at end of file
