How can I change the default location of log4j2.xml in Java Spring Boot?

后端 未结 6 1311
醉梦人生
醉梦人生 2020-12-14 09:37

Log4j2 is working nicely with Spring Boot through the log4j2.xml configuration file in the root classpath, exactly as the documentation states.

When try

6条回答
  •  轮回少年
    2020-12-14 09:50

    As mentioned in the log4j2 documentation here, you can include a file named log4j2.component.properties in your resources folder (or anywhere in the classpath) and inside that file, you can provide the name of the file location (or a new file name) like this:

    log4j.configurationFile=path/to/log4j2.xml
    

    or

    log4j.configurationFile=classpath:log4j2-custom.xml (if the file is on the classpath)
    

    You can alternatively provide the config file location via the context-param fields of web.xml as mentioned here, but I haven't tried that option

    (This works with Spring Boot too)

提交回复
热议问题