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/21 03:22:53 UTC

[logging-log4j2] branch master updated (f11dc6d -> 9cc2967)

This is an automated email from the ASF dual-hosted git repository.

rgoers pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.


    from f11dc6d  LOG4J2-3334 - Create test to try to verify the problem
     new af0d269  LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified
     new 9cc2967  LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/logging/log4j/LogManager.java  |  2 +-
 log4j-spring-boot/pom.xml                          |  9 ++++
 .../spring/boot/Log4j2SpringBootInitTest.java      | 62 ++++++++++++++++++++++
 .../src/test/resources/application.yml             |  5 ++
 .../src/test/resources/log4j2-springProfile.xml    |  3 +-
 src/changes/changes.xml                            |  3 ++
 6 files changed, 82 insertions(+), 2 deletions(-)
 create mode 100644 log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootInitTest.java
 create mode 100644 log4j-spring-boot/src/test/resources/application.yml

[logging-log4j2] 02/02: LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified

Posted by rg...@apache.org.
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

commit 9cc2967a4f900862d6999bf9eb9715555af9e056
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Feb 20 18:43:10 2022 -0700

    LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified
---
 log4j-spring-boot/pom.xml                          |  9 ++++
 .../spring/boot/Log4j2SpringBootInitTest.java      | 62 ++++++++++++++++++++++
 .../src/test/resources/application.yml             |  5 ++
 .../src/test/resources/log4j2-springProfile.xml    |  3 +-
 src/changes/changes.xml                            |  3 ++
 5 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/log4j-spring-boot/pom.xml b/log4j-spring-boot/pom.xml
index 5e104d8..37652b6 100644
--- a/log4j-spring-boot/pom.xml
+++ b/log4j-spring-boot/pom.xml
@@ -70,6 +70,15 @@
       <artifactId>spring-context-support</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.junit.platform</groupId>
+      <artifactId>junit-platform-commons</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit-pioneer</groupId>
+      <artifactId>junit-pioneer</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.hamcrest</groupId>
       <artifactId>hamcrest</artifactId>
       <scope>test</scope>
diff --git a/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootInitTest.java b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootInitTest.java
new file mode 100644
index 0000000..fd36fc2
--- /dev/null
+++ b/log4j-spring-boot/src/test/java/org/apache/logging/log4j/spring/boot/Log4j2SpringBootInitTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.spring.boot;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.jupiter.api.Test;
+import org.junitpioneer.jupiter.SetSystemProperty;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@SetSystemProperty(key = "spring.profiles.active", value = "prod")
+@SetSystemProperty(key = "log4j2.loggerContextFactory", value = "org.apache.logging.log4j.core.impl.Log4jContextFactory")
+@SpringBootTest
+public class Log4j2SpringBootInitTest {
+
+    @Test
+    public void testEnvironment() {
+        LoggerContext context = (LoggerContext) LogManager.getContext(false);
+        ListAppender app = context.getConfiguration().getAppender("Out");
+        assertNotNull(app);
+        assertEquals(1, app.getMessages().size());
+        assertEquals("Started: log4j-spring-boot", app.getMessages().get(0));
+    }
+
+    @SpringBootApplication
+    public static class SpringTestApplication implements ApplicationRunner {
+        private final Logger LOGGER = LogManager.getLogger("org.apache.logging.log4j.core.springtest");
+        public static void main(String[] args) {
+            SpringApplication.run(SpringTestApplication.class, args);
+        }
+
+        @Override
+        public void run(ApplicationArguments args) throws Exception {
+            SpringLookup lookup = new SpringLookup();
+            LOGGER.info("Started: {}", lookup.lookup("spring.application.name"));
+        }
+    }
+}
+
diff --git a/log4j-spring-boot/src/test/resources/application.yml b/log4j-spring-boot/src/test/resources/application.yml
new file mode 100644
index 0000000..1723142
--- /dev/null
+++ b/log4j-spring-boot/src/test/resources/application.yml
@@ -0,0 +1,5 @@
+spring:
+  application:
+    name: log4j-spring-boot
+logging:
+  config: classpath:log4j2-springProfile.xml
\ No newline at end of file
diff --git a/log4j-spring-boot/src/test/resources/log4j2-springProfile.xml b/log4j-spring-boot/src/test/resources/log4j2-springProfile.xml
index c3a3783..7ac3322 100644
--- a/log4j-spring-boot/src/test/resources/log4j2-springProfile.xml
+++ b/log4j-spring-boot/src/test/resources/log4j2-springProfile.xml
@@ -26,12 +26,13 @@
     </SpringProfile>
     <SpringProfile name="prod">
       <List name="Out">
+        <PatternLayout pattern="%m"/>
       </List>
     </SpringProfile>
 
   </Appenders>
   <Loggers>
-    <Logger name="org.apache.test" level="trace" additivity="false">
+    <Logger name="org.apache.logging.log4j.core.springtest" level="trace" additivity="false">
       <AppenderRef ref="Out"/>
     </Logger>
     <Root level="error">
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d5aae60..fac3845 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -176,6 +176,9 @@
     </release>
     <release version="2.17.2" date="20YY-MM-DD" description="GA Release 2.17.2">
       <!-- FIXES -->
+      <action issue="LOG4J2-3304" dev="rgoers" type="fix" due-to="francis-FY">
+        Flag LogManager as initiialized if the LoggerFactory is provided as a property.
+      </action>
       <action issue="LOG4J2-3405" dev="rgoers" type="fix">
         Document that the Spring Boot Lookup requires the log4j-spring-boot dependency.
       </action>

[logging-log4j2] 01/02: LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified

Posted by rg...@apache.org.
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

commit af0d269b13f777992db00ef1829b827900a4e8d6
Author: Ralph Goers <rg...@apache.org>
AuthorDate: Sun Feb 20 18:42:34 2022 -0700

    LOG4J2-3304 - Mark LogManager as initialized when a LoggerFactory is specified
---
 log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
index a67dcbd..887e1ed 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/LogManager.java
@@ -122,8 +122,8 @@ public class LogManager {
                         + "Please add log4j-core to the classpath. Using SimpleLogger to log to the console...");
                 factory = SimpleLoggerContextFactory.INSTANCE;
             }
-            LogManagerStatus.setInitialized(true);
         }
+        LogManagerStatus.setInitialized(true);
     }
 
     /**