问题
I using log4j2
. My config look like this:
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="warn">
<Properties>
<Property name="pattern">{%X{taskId}} %date{yyyy-MM-dd HH:mm:ss.SSS} %level %M(%F:%L) - %msg%n</Property>
<Property name="folder">logs</Property>
<Property name="info-filename">test</Property>
<Property name="error-filename">test-error</Property>
</Properties>
<Appenders>
<RollingFile name="file" fileName="${folder}/${info-filename}.log" filePattern="${folder}/$${date:yyyy-MM-dd}/${info-filename}-%d{yyyy-dd-MM}.%i.log.gz">
<PatternLayout pattern="${pattern}" />
<Policies>
<SizeBasedTriggeringPolicy size="4 GB" />
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="999999"/>
</RollingFile>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="${pattern}" />
</Console>
<RollingFile name="file-error" fileName="${folder}/${error-filename}.log" filePattern="${folder}/$${date:yyyy-MM-dd}/${error-filename}-%d{yyyy-dd-MM}.%i.log.gz">
<PatternLayout pattern="${pattern}" />
<Policies>
<SizeBasedTriggeringPolicy size="4 GB" />
<TimeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="999999"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="file"/>
<AppenderRef ref="file-error" level="error" />
</Root>
<Logger name="org.apache.http" level="error">
<AppenderRef ref="file-error" level="error" />
</Logger>
<Logger name="org.springframework.ws.client" level="error">
<AppenderRef ref="file-error" level="error" />
</Logger>
</Loggers>
</Configuration>
I want the folder logs
and all the files attached to it to be created with rights rw-rw-r--
. Also, for the group and the owner to have the same as the user who launched the program. How can I configure my log4j2
to do this?
回答1:
Log4j2 since 2.9.0 supports such feature: https://issues.apache.org/jira/browse/LOG4J2-1699
You can use additional attributes for element RollingFile
like
<RollingFile ... filePermissions="rw-rw-r--">
来源:https://stackoverflow.com/questions/49810431/file-permissions-log4j2