You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Overriding the log level for a specific package with an environment variable does not work as expected when using an environment prefix.
Files to reproduce the problem
Application.kt:
package com.example.springboot
import com.example.springboot.a.A
import com.example.springboot.b.B
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class Application
fun main(args: Array<String>) {
val application = SpringApplication(Application::class.java)
application.environmentPrefix = "prefix"
application.run(*args)
A().log()
B().log()
}
A.kt in package com.example.springboot.a:
package com.example.springboot.a
import org.slf4j.LoggerFactory
class A {
private val logger = LoggerFactory.getLogger(A::class.java)
fun log() {
logger.atInfo().log("Some info log")
logger.atDebug().log("Some debug log")
}
}
B.kt in package com.example.springboot.b:
package com.example.springboot.b
import org.slf4j.LoggerFactory
class B {
private val logger = LoggerFactory.getLogger(B::class.java)
fun log() {
logger.atInfo().log("Some info log")
logger.atDebug().log("Some debug log")
}
}
Expected behaviour
If the application is started with the environment variable PREFIX_LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG the debug statement from class B should be logged.
Actual behaviour
No debug statement is logged.
Further observations
If the application is started with two environment variables, one using the prefix and the other not, the debug statement is logged (i.e., started with LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG;PREFIX_LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG).
However, if started with only one of the two environment variables, no debug statement is logged.
The log level can be adjusted as execpted by setting the environment variable LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG if no environment prefix is set in Application.kt.
The debug level can be adjusted as expected in the application.yaml file:
logging:
level:
root: INFO
com.example.springboot.b: DEBUG
The text was updated successfully, but these errors were encountered:
wilkinsona
changed the title
Overriding log level with an environment variable broken when using an environment prefix
Overriding log level with an environment variable does not work when using an environment prefix
Nov 27, 2024
Overriding the log level for a specific package with an environment variable does not work as expected when using an environment prefix.
Files to reproduce the problem
Application.kt
:A.kt
in packagecom.example.springboot.a
:B.kt
in packagecom.example.springboot.b
:application.yaml
:This zip file contains the sample project.
Expected behaviour
If the application is started with the environment variable
PREFIX_LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG
the debug statement from classB
should be logged.Actual behaviour
No debug statement is logged.
Further observations
LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG;PREFIX_LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG
).However, if started with only one of the two environment variables, no debug statement is logged.
LOGGING_LEVEL_COM_EXAMPLE_SPRINGBOOT_B=DEBUG
if no environment prefix is set inApplication.kt
.application.yaml
file:The text was updated successfully, but these errors were encountered: