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
I get similar issue, on application start following empty file might be generated:
LOG_PATH_IS_UNDEFINEDLOG_FILE_IS_UNDEFINEDLogging related config in application.yml, is read after logback-spring.xml is parsed, thus can't read it.
I found 3 possible solutions, choose one that best fit your case:
Move logging config from application.yml to bootstrap.yml, this will need spring-cloud dependency to make it work.
bootstrap.yml is read before logback-spring.xml.spring-cloud, this probably won't be your best choice, since the extra dependencies is unnecessary.Define path & file in logback-spring.xml directly.
e.g
<configuration>
<springProperty name="LOG_PATH" source="logging.path" defaultValue="logs/" />
<springProperty name="LOG_FILE" source="logging.file" defaultValue="app.log" />
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.
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.
logback-spring.xml file mentioned above, might be logback.xml or some other name in your case.