You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2022/02/20 07:49:23 UTC
[logging-log4j2] branch release-2.x updated: LOG4J2-3334 - Create test to try to verify the problem
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 5e052c9 LOG4J2-3334 - Create test to try to verify the problem
5e052c9 is described below
commit 5e052c903bcbc29c8f4be5e7b08413c1e121312a
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Feb 20 00:49:06 2022 -0700
LOG4J2-3334 - Create test to try to verify the problem
---
.../core/config/ConfiguratorSetLevelTest.java | 61 ++++++++++++++++++++++
log4j-core/src/test/resources/log4j-set-level.xml | 37 +++++++++++++
2 files changed, 98 insertions(+)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java
new file mode 100644
index 0000000..ac04f24
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.logging.log4j.core.config;
+
+import java.io.File;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.junit.LoggerContextSource;
+import org.apache.logging.log4j.junit.Named;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@Tag("functional")
+@LoggerContextSource("log4j-set-level.xml")
+public class ConfiguratorSetLevelTest {
+
+ private final ListAppender app1;
+ private final LoggerContext loggerContext;
+ private org.apache.logging.log4j.Logger logger1;
+
+ public ConfiguratorSetLevelTest(final LoggerContext context, @Named("LIST1") final ListAppender first) {
+ this.loggerContext = context;
+ logger1 = context.getLogger("org.apache.logging");
+ app1 = first.clear();
+ }
+
+ @Test
+ public void testSetLevel() {
+ Logger logger = loggerContext.getLogger(ConfiguratorSetLevelTest.class);
+ Configurator.setLevel(logger, Level.DEBUG);
+ LoggerConfig loggerConfig = ((AbstractConfiguration)loggerContext.getConfiguration())
+ .getLogger(ConfiguratorSetLevelTest.class.getName());
+ assertNotNull(loggerConfig);
+ assertEquals(Level.DEBUG, loggerConfig.getLevel());
+ assertEquals(0, loggerConfig.getAppenderRefs().size());
+ logger.trace("Test trace message");
+ logger.debug("Test debug message");
+ assertEquals(1, app1.getEvents().size());
+ }
+}
diff --git a/log4j-core/src/test/resources/log4j-set-level.xml b/log4j-core/src/test/resources/log4j-set-level.xml
new file mode 100644
index 0000000..06de5cd
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-set-level.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="ERROR" name="XMLConfigTest">
+ <Appenders>
+ <Console name="STDOUT">
+ <PatternLayout pattern="%m%n"/>
+ </Console>
+ <List name="LIST1"/>
+ </Appenders>
+
+ <Loggers>
+ <Logger name="org.apache.logging" level="trace" additivity="false">
+ <AppenderRef ref="LIST1" level="trace"/>
+ </Logger>>
+
+ <Root level="error">
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+
+</Configuration>
\ No newline at end of file