-Dlogback.configurationFile=logback.xml ignored when running Spring-Boot

后端 未结 8 739
太阳男子
太阳男子 2020-12-23 19:57

We have a spring-boot 1.0.RC1 application, with logback configured for logging and a logback.xml file in src/test/resources. When we run spring-boot from maven, the logback

相关标签:
8条回答
  • 2020-12-23 20:01

    Add logback file path in application.properties file . Example test folder contains app.jar and config folder as below
    test
    |- app.jar
    |- config
            |--- application.properties
            |--- logback.xml

    Then add logging.config:config\\logback.xml. Then try , it will work

    0 讨论(0)
  • 2020-12-23 20:08

    Assuming you have spring logback configurations in config directory, the command below will add external file by overriding the existing file (if any) inside the application:

    java -jar -Dlogging.config=./config/logback-spring.xml app.jar --spring.config.location=./config/application.properties

    0 讨论(0)
  • 2020-12-23 20:16

    I know this post is a bit old but adding the following to application.properties is a quick workaround based on Dave Syer's answer:

    logging.config=${logback.configurationFile}
    
    0 讨论(0)
  • 2020-12-23 20:20

    Not quite right. logback.configurationFile is not managed by Spring (i.e. env var replacement or so), but logback will still pick it up. At least that's my understanding of the docs and my practical experience.

    0 讨论(0)
  • 2020-12-23 20:21

    If anything is Spring related, I always prefer and suggest going to Spring Guides/Reference notes first before jumping and putting question into SO.

    Anything anybody need related to Logback (Spring Boot Context) is - Here.

    0 讨论(0)
  • 2020-12-23 20:23

    The default strategy assumes that if you don't have a logback.xml (or one of the other standard file names) in the classpath then you must be happy with the defaults (see LogbackLoggingSystem for details). Spring Boot tries to unify the external configuration switches for common logging sytems, so it looks in logging.config (it didn't know about logback.configurationFile). You could use that instead (i.e. logging.config=file:./src/test/resources/logback.xml), or make sure your config file is on the classpath.

    0 讨论(0)
提交回复
热议问题