Set Logging Level in Spring Boot via Environment Variable

Setting log levels via environment variables can only be done for Packages but not for Classes

I had the same problem as the OP. And I was wondering why some of the users here reported that the proposed solutions worked well while others responded they didn't.
I'm on Spring Boot 2.1 and the problem obviously changed a bit over the last years, but the current situation is as follows:

TL;DR

Setting the log level for a package works:

LOGGING_LEVEL_COM_ACME_PACKAGE=DEBUG

While setting the log level for a specific class has no effect:

LOGGING_LEVEL_COM_ACME_PACKAGE_CLASS=DEBUG

How can that be?

Have a look at Spring Boot's LoggingApplicationListener.
If you'd debug it and set a breakpoint in the highlighted code block, you'd see that the log level definition for a class com.acme.mypackage.MyClass becomes com.acme.mypackage.myclass.
So a log level definition for a class looks exactly like a log level definition for a package.

This is related to Spring's Relaxed Binding, which proposes an upper case notation for environment variables. Thus the typical camel case notation of a class is not visible for the LoggingApplicationListener: The environment variable for MyClass has to be defined as MYCLASS and will be available as myclass in Spring's Environment (this example ignores the fully-qualified name of the class).

Once the camel case notation of the class is lost, during runtime there's no chance to recover the original class name. Thus log definitions in environment variables don't work for classes but only for packages.


This is just an idea, but did you try setting

_JAVA_OPTIONS=-Dlogging.level.org.springframework=TRACE?

Theoretically, this way -Dlogging.level.org.springframework=TRACE will be passed as default JVM argument and should affect every JVM instance in your environment.