SpringBoot with LogBack creating LOG_FILE_IS_UNDEFINED folder

前端 未结 1 1400
长发绾君心
长发绾君心 2021-01-11 17:33

I am using SpringBoot with LogBack and I am trying to direct all log-statements of one specific package (here shown as \"com.example.somepackagename\") to a file. All other

1条回答
  •  抹茶落季
    2021-01-11 17:48

    I get similar issue, on application start following empty file might be generated:

    • LOG_PATH_IS_UNDEFINED
    • LOG_FILE_IS_UNDEFINED

    Reason

    Logging related config in application.yml, is read after logback-spring.xml is parsed, thus can't read it.


    Possible solutions

    I found 3 possible solutions, choose one that best fit your case:

    1. Move logging config from application.yml to bootstrap.yml, this will need spring-cloud dependency to make it work.

      • This works because bootstrap.yml is read before logback-spring.xml.
      • If you are not using spring-cloud, this probably won't be your best choice, since the extra dependencies is unnecessary.
    2. Define path & file in logback-spring.xml directly.
      e.g

       
           
           
      

      In this case, might need to add "logback-spring.xml" to each sub project, if the log file names need to be different, and can't simply put the config file in a shared common dependency.

    3. Just keep the config in application.yml, and ignore the generated empty files by setting .gitinore.
      e.g

       LOG_*_IS_UNDEFINED
      

      In this case, the logs are still written to the file specified by application.yml, though the empty file is generate.


    Tips

    • The logback-spring.xml file mentioned above, might be logback.xml or some other name in your case.

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