-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logback configuration defined via JAVA_TOOL_OPTIONS is ignored (#9009)
Previously, we only checked the classpath for logback configuration files, and when refreshing we ignored the `logback.configurationFile` setting. This PR checks the filesystem if the config cannot be found on the classpath It also adds `logback.configurationFile` as an optional property that points to the location of the config for when we refresh the configuration. `logback.configurationFile` has precedence over the existing `logger.config` property
- Loading branch information
Showing
7 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test-suite-logback-external-configuration/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.convention-test-library") | ||
} | ||
|
||
dependencies { | ||
testAnnotationProcessor(projects.injectJava) | ||
|
||
testImplementation(libs.managed.micronaut.test.spock) { | ||
exclude(group="io.micronaut", module="micronaut-aop") | ||
} | ||
testImplementation(projects.context) | ||
testImplementation(projects.injectGroovy) | ||
testImplementation(libs.managed.logback) | ||
testImplementation(projects.management) | ||
testImplementation(projects.httpClient) | ||
|
||
testRuntimeOnly(projects.httpServerNetty) | ||
} |
16 changes: 16 additions & 0 deletions
16
test-suite-logback-external-configuration/src/external/external-logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<configuration> | ||
|
||
<!-- This should be ignored, as we have programmatic configuration --> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="external.logging" level="TRACE" /> | ||
</configuration> |
56 changes: 56 additions & 0 deletions
56
...ernal-configuration/src/test/groovy/io/micronaut/logback/ExternalConfigurationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.micronaut.logback | ||
|
||
import ch.qos.logback.classic.Level | ||
import ch.qos.logback.classic.Logger | ||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.runtime.server.EmbeddedServer | ||
import org.slf4j.LoggerFactory | ||
import spock.lang.See | ||
import spock.lang.Specification | ||
import spock.util.environment.RestoreSystemProperties | ||
|
||
@See("https://logback.qos.ch/manual/configuration.html#auto_configuration") | ||
class ExternalConfigurationSpec extends Specification { | ||
|
||
@RestoreSystemProperties | ||
def "should use the external configuration"() { | ||
given: | ||
System.setProperty("logback.configurationFile", "src/external/external-logback.xml") | ||
|
||
when: | ||
Logger fromXml = (Logger) LoggerFactory.getLogger("i.should.not.exist") | ||
Logger external = (Logger) LoggerFactory.getLogger("external.logging") | ||
|
||
then: 'logback.xml is ignored as we have set a configurationFile' | ||
fromXml.level == null | ||
|
||
and: 'external configuration is used' | ||
external.level == Level.TRACE | ||
} | ||
|
||
@RestoreSystemProperties | ||
def "should still use the external config if custom levels are defines"() { | ||
given: | ||
System.setProperty("logback.configurationFile", "src/external/external-logback.xml") | ||
|
||
when: | ||
def server = ApplicationContext.run(EmbeddedServer, [ | ||
"logger.levels.app.customisation": "DEBUG" | ||
]) | ||
Logger fromXml = (Logger) LoggerFactory.getLogger("i.should.not.exist") | ||
Logger custom = (Logger) LoggerFactory.getLogger("app.customisation") | ||
Logger external = (Logger) LoggerFactory.getLogger("external.logging") | ||
|
||
then: 'logback.xml is ignored as we have set a configurationFile' | ||
fromXml.level == null | ||
|
||
and: 'custom levels are still respected' | ||
custom.level == Level.DEBUG | ||
|
||
and: 'external configuration is used' | ||
external.level == Level.TRACE | ||
|
||
cleanup: | ||
server.stop() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
test-suite-logback-external-configuration/src/test/resources/logback.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<configuration> | ||
|
||
<!-- This should be ignored, as we have programmatic configuration --> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
<logger name="i.should.not.exist" level="TRACE" /> | ||
</configuration> |