简体   繁体   中英

Configuring log4j file in Spring Boot using Java

I use a JSON file for log4j configuration in a Spring Boot project. I excluded spring-boot-starter-logging and added spring-boot-starter-log4j2 in the pom file.

If I place the log4j2 file on classpath , I see logs are written to files properly, as designed. However, when I set -Dlog4j.configurationFile on start up, the log files are created but are empty and all the logs are written to the console. To test if the file is read, in debug I see that the JSON file is found and read. Also, when I set a fake location, the app does not start at all and instead throws a file not found exception. It shows that the configuration file is found, I believe.

log4j version is 2.7 .
Spring boot version is 1.5.10 .

Can you please check the Appender added in the log4j configuration. The default would be ConsoleAppender. Can you please try adding RollingFileAppender

Also you may have to create the log directory which should be the immediate parent of the desired log file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM