This is an automated email from the ASF dual-hosted git repository. clebertsuconic pushed a commit to branch new-logging in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
commit eb8e93b6ad2871e855f12c96864117988fa1a776 Author: Robbie Gemmell <[email protected]> AuthorDate: Mon Jul 11 16:15:14 2022 +0100 basic logging config and some more on AssertionLoggerHandler to get some tests using it working --- .../artemis/logs/AssertionLoggerHandler.java | 51 ++++++++++++++-------- pom.xml | 6 ++- tests/config/log4j2-tests-config-CI.properties | 38 ++++++++++++++++ tests/config/log4j2-tests-config.properties | 32 ++++++++++++++ 4 files changed, 108 insertions(+), 19 deletions(-) diff --git a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java index 4bb25932f2..269745e4d5 100644 --- a/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java +++ b/artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java @@ -29,6 +29,8 @@ import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; /** * This class contains a tool where programs could intercept for LogMessage given an interval of time between {@link #startCapture()} @@ -36,29 +38,25 @@ import org.apache.logging.log4j.core.config.Property; * * Be careful with this use as this is intended for testing only (such as testcases) */ -public class AssertionLoggerHandler extends AbstractAppender { - - public enum LogLevel { - ERROR(Level.ERROR), - WARN(Level.WARN), - INFO(Level.INFO), - DEBUG(Level.DEBUG), - TRACE(Level.TRACE); - Level implLevel; +@Plugin(name = "AssertionLoggerHandler", category = "Core", elementType = "appender") +public class AssertionLoggerHandler extends AbstractAppender { - private LogLevel(Level implLevel) { - this.implLevel = implLevel; - } + private static final Map<String, LogEvent> messages = new ConcurrentHashMap<>(); + private static List<String> traceMessages; + private static volatile boolean capture = false; - private Level toImplLevel() { - return implLevel; + public static class Builder<B extends Builder<B>> extends AbstractAppender.Builder<B> implements org.apache.logging.log4j.core.util.Builder<AssertionLoggerHandler> { + @Override + public AssertionLoggerHandler build() { + return new AssertionLoggerHandler(getName(), getFilter(), getOrCreateLayout(), isIgnoreExceptions(), getPropertyArray()); } } - private static final Map<String, LogEvent> messages = new ConcurrentHashMap<>(); - private static List<String> traceMessages; - private static volatile boolean capture = false; + @PluginBuilderFactory + public static <B extends Builder<B>> B newBuilder() { + return new Builder<B>().asBuilder(); + } protected AssertionLoggerHandler(String name, Filter filter, Layout<? extends Serializable> layout, boolean ignoreExceptions, Property[] properties) { super(name, filter, layout, ignoreExceptions, properties); @@ -221,4 +219,23 @@ public class AssertionLoggerHandler extends AbstractAppender { clear(); traceMessages = null; } + + public enum LogLevel { + ERROR(Level.ERROR), + WARN(Level.WARN), + INFO(Level.INFO), + DEBUG(Level.DEBUG), + TRACE(Level.TRACE); + + Level implLevel; + + LogLevel(Level implLevel) { + this.implLevel = implLevel; + } + + private Level toImplLevel() { + return implLevel; + } + } + } diff --git a/pom.xml b/pom.xml index 8bb64ab7ae..22f49428e0 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ <staging.siteURL>scp://people.apache.org/x1/www/activemq.apache.org</staging.siteURL> <retryTests>false</retryTests> - <logging.config>logging.properties</logging.config> + <logging.config>log4j2-tests-config.properties</logging.config> <modular.jdk.surefire.arg>--add-modules java.sql,jdk.unsupported </modular.jdk.surefire.arg> <activemq-artemis-native-version>2.0.0-SNAPSHOT</activemq-artemis-native-version> @@ -235,6 +235,7 @@ -Djava.library.path="${activemq.basedir}/target/bin/lib/linux-x86_64:${activemq.basedir}/target/bin/lib/linux-i686" -Djgroups.bind_addr=localhost -Djava.net.preferIPv4Stack=true -Dbasedir=${basedir} -Djdk.attach.allowAttachSelf=true + -Dlog4j2.configurationFile="file:${activemq.basedir}/tests/config/${logging.config}" </activemq-surefire-argline> <activemq.basedir>${project.basedir}</activemq.basedir> <skipOWASP>true</skipOWASP> @@ -1286,7 +1287,7 @@ <id>tests-CI</id> <properties> <!-- notice I did not intend to use retryTests on this profile, as this will be optional depending on where you run the tests --> - <logging.config>logging-CI.properties</logging.config> + <logging.config>log4j2-tests-config-CI.properties</logging.config> </properties> </profile> <profile> @@ -1349,6 +1350,7 @@ <jacoco.agent /> <activemq-surefire-argline> + -Dlog4j2.configurationFile="file:${activemq.basedir}/tests/config/${logging.config}" -Djava.library.path="${activemq.basedir}/activemq-artemis-native/bin" -Djgroups.bind_addr=localhost -Dorg.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory.localBindAddress=localhost -Djava.net.preferIPv4Stack=true -Dbasedir=${basedir} @{jacoco.agent} -Djacoco.agent=@{jacoco.agent} diff --git a/tests/config/log4j2-tests-config-CI.properties b/tests/config/log4j2-tests-config-CI.properties new file mode 100644 index 0000000000..4ecac73492 --- /dev/null +++ b/tests/config/log4j2-tests-config-CI.properties @@ -0,0 +1,38 @@ +# 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. + +# Log4J 2 configuration used in tests in CI +rootLogger = INFO, Console, Test + +logger.activemq.name=org.apache.activemq +logger.activemq.level=INFO + +# quorum logger levels +logger.curator.name=org.apache.curator +logger.curator.level=WARN +logger.zookeeper.name=org.apache.zookeeper +logger.zookeeper.level=WARN + +# Console appender +appender.console.type=Console +appender.console.name=Console +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=[%t] %d{HH:mm:ss,SSS} %-5level [%logger] %msg%n + +# Test appender org.apache.activemq.artemis.logs.AssertionLoggerHandler +appender.test.type=AssertionLoggerHandler +appender.test.name=Test +appender.test.layout.type=PatternLayout +appender.test.layout.pattern=[%t] %d{HH:mm:ss,SSS} %-5level [%logger] %msg%n diff --git a/tests/config/log4j2-tests-config.properties b/tests/config/log4j2-tests-config.properties new file mode 100644 index 0000000000..b6dc034c43 --- /dev/null +++ b/tests/config/log4j2-tests-config.properties @@ -0,0 +1,32 @@ +# 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. + +# Log4J 2 configuration used in tests. +rootLogger = INFO, Console, Test + +logger.activemq.name=org.apache.activemq +logger.activemq.level=INFO + +# Console appender +appender.console.type=Console +appender.console.name=Console +appender.console.layout.type=PatternLayout +appender.console.layout.pattern=[%t] %d{HH:mm:ss,SSS} %-5level [%logger] %msg%n + +# Test appender org.apache.activemq.artemis.logs.AssertionLoggerHandler +appender.test.type=AssertionLoggerHandler +appender.test.name=Test +appender.test.layout.type=PatternLayout +appender.test.layout.pattern=[%t] %d{HH:mm:ss,SSS} %-5level [%logger] %msg%n
