Should it be possible to set logging levels through environment variables alone in a Spring Boot application?
I don\'t want to use application.properties
Folks can anyone explain why this is not working?
$ export LOGGING_LEVEL_COM_ACME=ERROR
For all other configuration using environment variables as an override seems to work with no issues, for example:
$ export EUREKA_CLIENT_ENABLED=false
Thanks.
I also tried to set logging level via environment variable but as already mentioned it is not possible by using environment variable with upper case name, eg. LOGGING_LEVEL_ORG_SPRINGFRAMEWORK=DEBUG
. I also didn't want to do it via application.properties
or _JAVA_OPTIONS
.
After digging into class org.springframework.boot.logging.LoggingApplicationListener
I've checked that spring boot tries to set logging level DEBUG
to ORG_SPRINGFRAMEWORK
package which is not real package name. So conclusion is that you can use environment variable to set logging level but it needs to be in the form:
LOGGING_LEVEL_org.springframework=DEBUG
or
logging.level.org.springframework=DEBUG
Tested on spring boot 1.5.3
I would anyway suggest you to use Spring profiles:
Create 2 properties files:
application-local.properties
and
application-remote.properties
(profile names can be different obviously)
Set the logging level in each file accordingly (logging.level.org.springframework
)
Run your application with -Dspring.profiles.active=local
locally and -Dspring.profiles.active=remote
for CF.
Also using Spring Boot (v1.2.3) in Cloud Foundry, I've found that it is possible to adjust the root logging level using an environment variable as follows:
$ cf set-env <app name> LOGGING_LEVEL_ROOT DEBUG
Unfortunately, it does not appear to be possible to dial-down the logging level for specific packages (at least with the version of Java Buildpack and Spring Boot I am using). For example adding the following in addition to the above does not reduce the log level for Spring framework:
$ cf set-env <app name> LOGGING_LEVEL_ORG_SPRINGFRAMEWORK INFO
If you are using something like Splunk to gather your logs, you may be able to filter out the noise, however.
Another alternative which looks promising could be based on customisation of the build pack's arguments option (see here):
$ cf set-env <app name> '{arguments: "-logging.level.root=DEBUG -logging.level.org.springframework=INFO"}'
Sadly, I couldn't get this to actually work. I certainly agree that being able to reconfigure logging levels at package level without changing the application code would be handy to get working.