log4j log file access Ubuntu (Tomcat)

2019-05-23 01:06发布

问题:

I'm using log4j library in my Java Spring Project

When I run my web app on my local Windows machine everything goes ok.

When I deploy my application to Digital Ocean Ubuntu server I get runtime error which I can't fix

logj4.properties file which I use for windows and everything runs ok

log4j.rootLogger=INFO, file
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=C:\\TMP\\log_file.log
    log4j.appender.file.MaxFileSize=1MB
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

and logj4.properties file which I use for ubuntu and get runtime error

  log4j.rootLogger=INFO, file
        log4j.appender.file=org.apache.log4j.RollingFileAppender
        log4j.appender.file.File=\\tmp\\log_file.log
        log4j.appender.file.MaxFileSize=1MB
        log4j.appender.file.layout=org.apache.log4j.PatternLayout
        log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

ERROR

log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: TMP\log_file.log (Permission denied)

Does anyone know how to overcome this error?