Set Logging Level in Spring Boot via Environment Variable

后端 未结 10 1095
刺人心
刺人心 2020-12-23 08:57

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

10条回答
  •  被撕碎了的回忆
    2020-12-23 10:03

    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  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  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  '{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.

提交回复
热议问题