Search code examples
springspring-bootlogback

Specify default value for a logback property, in spring-boot


In spring-boot application, I am trying to config a default dir for logback.

Usually, in logback.xml I would config it this way:

<property name="logFile.dir" value="${catalina.home:-/tmp}/logs" />

The separator is :-.

But, in application.properties:

I have to config it this way:

logging.file=${catalina.home:/tmp}/logs/sportslight.log

Need to change the separator from :- to :.

The questions are:

  • In logback.xml, which is the correct separator, :- or :?
  • In application.properties, why only : works, is it because spring-boot would handle it first before pass the value to logback?

Solution

  • In logback.xml the correct separator is :-. More details in the logback docs.

    In Spring the correct separator is : since Spring supports the ${my.property:defaultValue} syntax. More details in the PlaceholderConfigurerSupport doc.

    So, when faced with a choice of default value separator for variable substitution the logback author(s) chose :- and the Spring author(s) chose :.