简体   繁体   中英

log4j how to specify log file relative path

This is the log file for my log4j

log4j.rootLogger=DEBUG, FILE

    log4j.appender.FILE=org.apache.log4j.RollingFileAppender
    log4j.appender.FILE.file=/Applications/apache-tomcat-8.0.24/logs/myLog.log
    log4j.appender.FILE.Append=true
    log4j.appender.FILE.Encoding=UTF-8
    log4j.appender.FILE.MaxFileSize=10MB
    log4j.appender.FILE.MaxBackupIndex=10
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c:%L - %m%n

As you see, i specify the location of the log file like:

Application/bla bla bla

That works good when I deploy on Mac, but sometimes, I deploy on windows, so I have to change that location to

C:/bla bla bla

is there any way to make the path relative? I would like to create my custom log file always in the logs folder of apache on the server regardless of the operating system

Thanks

When you deploy a web app into tomcat the servlet code runs in the JVM instance of tomcat. So all relative paths are relative to the current working directory (CWD) of the tomcat process.

The "standard" CWD is %CATALINA_HOME%\\bin . To write into tomcat's log folder you logfile prefix should be ../logs/ like ../logs/myapp .

If you use maven, you can do:

resource filtering

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