java 文件权限log4j2

xkftehaa  于 2023-02-11  发布在  Java
关注(0)|答案(1)|浏览(193)

我使用log4j2 .我的配置看起来像这样:

<?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>

我希望使用rw-rw-r--权限创建文件夹logs和所有附加到它的文件。另外,组和所有者与启动程序的用户具有相同的权限。我如何配置我的log4j2来实现这一点?

67up9zun

67up9zun1#

Log4j2自2.9.0起支持以下功能:https://issues.apache.org/jira/browse/LOG4J2-1699
可以为元素RollingFile使用其他属性,例如

<RollingFile ... filePermissions="rw-rw-r--">

相关问题