'Specifying LoggingSystem property in Spring Boot doesn't override logback
Referencing, https://docs.spring.io/spring-boot/docs/2.5.9/reference/html/features.html#features.logging.custom-log-configuration
It mentions to add the following system variable with the fully qualified path to the LoggingSystem you want to use, so I added the following to my application.properties file:
org.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
After which I ran mvn clean install and ran my project using:
mvn -X spring-boot:run <set env vars> -f "$(pwd)"/ai-app/pom.xml
My pom has the following config:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I even tried setting the value to none in the properties but to no avail. It was still using logback.
In the code I access the logger as follows:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
...
...
...
private static final Logger LOGGER = LoggerFactory.getLogger(<class_name>.class);
Where below is a sample of the log output by the custom LOGGER
2022-04-04 18:02:04.639 INFO 58294 --- [nio-8443-exec-1] c.v.v.a.s.d.service.SomeServiceImpl : Files saved to successfully
I also tried passing in the variable via command in the two following ways:
1: -Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
2: spring-boot:run "-Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem"
both of which would be included as part of the command above to run the app.
If anyone has an idea what I have to do here it would be appreciated. From the docs is says that I should be able to override the default without having to exclude the logging starter and explicitly including the log4j starter.
Thanks in advance
EDIT:
after a discussion in the comments, I followed: https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#run.examples.system-properties (both adding jvmRunArgs + systemProperties in the pom as a var to the maven plugin) and got the following error when running mvn spring-boot:run:
[INFO] Attaching agents: []
[DEBUG] JVM argument(s): -Xverify:none -XX:TieredStopAtLevel=1 -Dorg.springframework.boot.logging.LoggingSystem=Log4J2LoggingSystem
[DEBUG] Classpath for forked process: /Us...
...
...
[DEBUG] Application argument(s): --safetyai.entities.libpostal.datadir=/Users/farazoman/Documents/workspace/extra/datadir/libpostal --spring.profiles.active=local
[DEBUG] Environment variable(s):
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/core/filter/AbstractFilter
...
...
...
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.9:run (default-cli) on project ai-app: Application finished with exit code: 1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.9:run (default-cli) on project ai-app: Application finished with exit code: 1
looks like the error is with, I may have to import log4j Core, although that doesn't look clear from the original doc :/
[DEBUG] Environment variable(s):
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/core/filter/AbstractFilter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
