Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, January 8, 2016

Set Logging Level in Spring Boot via Environment Variable

Set Logging Level in Spring Boot via Environment Variable


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 as I'm running on Cloud Foundry and want to pick up changes without a deploy (but after the app has restarted, or restaged to be more precise).

I've tried setting env vars like LOGGING_LEVEL_ORG_SPRINGFRAMEWORK=TRACE but that has no effect. Putting logging.level.org.springframework: TRACE in application.properties does work though.

Answer by Timekiller for Set Logging Level in Spring Boot via Environment Variable


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.

Answer by Micha Urbaniak for Set Logging Level in Spring Boot via Environment Variable


I would anyway suggest you to use Spring profiles:

  1. Create 2 properties files:

    application-local.properties and application-remote.properties

    (profile names can be different obviously)

  2. Set the logging level in each file accordingly (logging.level.org.springframework)

  3. Run your application with -Dspring.profiles.active=local locally and -Dspring.profiles.active=remote for CF.

Answer by Sparkle8 for Set Logging Level in Spring Boot via Environment Variable


Yes, you can control logging level using environment variable. Here is how I have implemented for my Spring Boot application, deployed on Cloud Foundry platform.

In you log configuration file provide placeholder for logging level to read value from environment variable. Default is INFO.

                    

And then, in CF deployment manifest file provide environment variable.

      applications:      - name: my-app-name        memory: 2048        env:          APP_LOGGING_LEVEL: DEBUG  

I hope this will help.

Answer by Eddie B for Set Logging Level in Spring Boot via Environment Variable


Here's an example using Logback with Janino to conditionally include different logging configs via properties or environmental variables... The base config, logback.xml is using conditionals for development console logging or production file logging... just drop the following files in /resources/


logback.xml


                                                                                                                              

dev.xml

                              utf-8              %-30([%p] [%c:%L]) ? %m%n%rEx                                                true                                    

pro.xml

                                                  FILE_NAME_PATTERN              7                                  ${FILE_LOG_PATTERN}                                  512                                                            

Answer by Damian O' Neill for Set Logging Level in Spring Boot via Environment Variable


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.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.