How to provide a default path for Log4j file insid

2019-08-02 18:55发布

问题:

a very good day to all .

I am asking a question , out of curisioty , may be this seem to be a foolish question also .

This is my log4j.properties file for a Application which will be in production very soon .

log4j.rootCategory=Info, A1

A1 is a DailyRollingFileAppender

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.file=D:/MyWEBLogs/MyWEB.log
log4j.appender.A1.datePattern='.'yyyy-MM-dd
log4j.appender.A1.append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} - %m%n

As you can see the file path i have mentioned here is D:/MyWEBLogs/MyWEB.log . (This works fine under Windows Environment )

But our Application will be taken as a war file and deployed inside Tomcat inside Linux Environment .

Inside Linux Environemnt , we are not sure about the path (That is whaere this tomcat resides there ...) and also as a user we have got limited permissions , like to create a file ---etc

So now my question is , what should be the best default path to be put in below line , so taht it runs anywhere in linux Environemnt , no matter where it is placed

log4j.appender.A1.file=D:/MyWEBLogs/MyWEB.log

回答1:

should be ${user.home}/appName/MyWEB.log , user generally has right to write in home dir