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 08:00:12 UTC

[logging-log4j2] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new f11dc6d  LOG4J2-3334 - Create test to try to verify the problem
f11dc6d is described below

commit f11dc6df9ae6367d96b73aed77e6e8c84e4cb4c7
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Feb 20 01:00:00 2022 -0700

    LOG4J2-3334 - Create test to try to verify the problem
---
 .../core/config/ConfiguratorSetLevelTest.java      | 58 ++++++++++++++++++++++
 .../src/test/resources/log4j-set-level.xml         | 37 ++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java
new file mode 100644
index 0000000..987fb8b
--- /dev/null
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfiguratorSetLevelTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.core.test.junit.Named;
+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-test/src/test/resources/log4j-set-level.xml b/log4j-core-test/src/test/resources/log4j-set-level.xml
new file mode 100644
index 0000000..06de5cd
--- /dev/null
+++ b/log4j-core-test/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