我试图将log4j2日志保存到用户主目录中,因为用户无权在应用程序安装的位置写入。
以下是我log4j设置的相关部分。不幸的是,它不能解析user.home,因此它会在应用程序运行的位置创建文件夹$user.home。
<?xml version="1.0" encoding="UTF-8"?>
<configuration name="defaultConfiguration" status="warn" strict="true" monitorInterval="270">
<properties>
<property name="patternlayout">%d{dd/MM/yyyy HH:mm:ss} %5p %c{1}:%L - %m%n
</property>
<property name="filename">${user.home}/niro/logs/niroDesk.log</property>
<property name="filenamePattern">${user.home}/niro/logs/niroDesk.log-%d{yyyy-MM-dd}.log.gz
</property>
</properties>
<appenders>
<appender name="Console" type="Console" target="SYSTEM_OUT">
<layout type="PatternLayout" pattern="${patternlayout}" />
</appender>
<!-- Log su file ogni giorno, e mantenimento degli ultimi 5 files -->
<RollingFile name="File" fileName="${filename}" filePattern="${filenamePattern}" bufferedIO="true" immediateFlush="true" append="true">
<PatternLayout pattern="${patternlayout}" />
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${user.home}/niro/logs" maxDepth="2">
<IfFileName glob="niroDesk*.log.gz" />
<IfLastModified age="7d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<appender name="AsyncFile" type="async" blocking="true" bufferSize="128">
<appender-ref ref="File" />
</appender>
</appenders>
<loggers>
<root level="error">
<appender-ref ref="Console" />
<appender-ref ref="AsyncFile" />
</root>
<logger level="warn" name="org.springframework" additivity="false">
<appender-ref ref="Console" />
<appender-ref ref="AsyncFile" />
</logger>
</loggers>
</configuration>
%d{dd/MM/yyyy HH:mm:ss} %5p %c{1}:%L - %m%n
${user.home}/niro/logs/niroDesk.log
${user.home}/niro/logs/niroDesk.log-%d{yyyy-MM-dd}.log.gz<appenders>
<appender name="Console" type="Console" target="SYSTEM_OUT">
<layout type="PatternLayout" pattern="${patternlayout}" />
</appender>
<!-- Log su file ogni giorno, e mantenimento degli ultimi 5 files -->
<RollingFile name="File" fileName="${filename}" filePattern="${filenamePattern}" bufferedIO="true" immediateFlush="true" append="true">
<PatternLayout pattern="${patternlayout}" />
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${user.home}/niro/logs" maxDepth="2">
<IfFileName glob="niroDesk*.log.gz" />
<IfLastModified age="7d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<appender name="AsyncFile" type="async" blocking="true" bufferSize="128">
<appender-ref ref="File" />
</appender>
</appenders>
<loggers>
<root level="error">
<appender-ref ref="Console" />
<appender-ref ref="AsyncFile" />
</root>
<logger level="warn" name="org.springframework" additivity="false">
<appender-ref ref="Console" />
<appender-ref ref="AsyncFile" />
</logger>
</loggers>
有解决这个问题的方法吗?