Log4j配置文件中指定日志路径

一、log4j.properties中使用变量

如果在log4j.properties中使用了变量${logPath},那么需要在使用logPath之前创建变量

log4j.appender.file.File=${logPath}/logs.log

方法一、运行Java时设置系统属性

java -DpropertyName=/Users/my projects/ui-basic/target

方法二、代码中指定

    static {
        System.setProperty("logPath", "/Users/my projects/ui-basic/target");
    }

二、使用绝对路径

log4j.appender.file.File=/Users/my projects/ui-basic/target/logs.log

三、使用相对路径

log4j.appender.file.File=logs.log
原文地址:https://www.cnblogs.com/xiaochengzi/p/14699285.html