简体   繁体   中英

How to change log4j2 logging path on tomcat?

I'm running a webapp on tomcat using spring-boot .

How could I change the log4j2.xml logging path dynamically? (eg by jvm args, property file, or else)?

So far I configured the log xml as follows:

<Configuration>
    <Properties>
        <property name="path">${bundle:application:log.path}</property>
    </Properties>
</Configuration>

With configuration file:

#application.properties:
log.path=d:/

Now I want to dynamically force the logpath to eg d:/log-test , but without having to modify my war file. Because on redeployment I would lose any manual configuration.

So how could I provide a different logging path?

I want to run multiple profiles on the same machine, so environment or system properties are of no use for me here.

You could do it in multiple ways mentioned here

if you want by environment variable then you could do something like:

${env:MY_LOG_PATH}

if System properties then:

${sys:MY_LOG_PATH}

As has already been suggested using ${sys:LOG_PATH} is probably the best solution. You do not have to modify the war, but you do have to run a tomcat for dev and a separate tomcat for test. Then just place set CATALINA_OPTS to include -DLOG_PATH=/my/log/path in setenv.sh or setenv.bat It really wouldn't make a lot of sense to have a single tomcat running both anyway.

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