nimavat.me

Java, Groovy, Grails, Spring, Vue, Ionic + Fun blog

How to externalize logback configuration

|

Grails 3 is built on top of springboot and takes advantage of springboot’s logging system. So springboots logging related configuration properties mentioned here can be used with Grails too.

Below is an example of how to use external logback configuration file, this applies to springboot too.

Specify the logback configuration file using logging.config

Spring boot uses the value of configuration logging.config to configure the logging system. logging.config accepts a spring resource pattern. 

If we wanted to use a different logback configuration for production environment, it can be configured as below.

File: application.yml (or application.groovy)

    environments:
      production:
        logging: #Logback config for production
           config: classpath:logback-prod.groovy

Note: if you use the classpath resource, make sure you actually put the logback-prod.groovy some where in tomcat classpath.

Below is an example of how to load the configuration from file system.

    environments:
      production:
        logging: #Logback config for production
           config:file:/<path-to-logback-config.groovy>

The example above uses a groovy configuration file. However logback xml configuration will work too.

You can specify the value of logging.config using a system property, If you dont want to hardcode the value of logging.config in application.yml.