[
https://issues.apache.org/jira/browse/LOG4J2-3565?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
su pei tao updated LOG4J2-3565:
-------------------------------
Description:
When you want split the log into different directories by period (day, hour,
minute, etc.), and use
[RollingRandomAccessFileAppender|https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender]
with a [DirectWrite
rollover|https://logging.apache.org/log4j/2.x/manual/appenders.html#RolloverStrategies],
the config should be:
{code:xml}
<RollingRandomAccessFile name="RollingFile"
filePattern="${baseDir}/%d{s}/%d{s}.log">
<PatternLayout header= "${LOG_HEADER}">
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
{code}
At that time when you create the first log of each directory, console shows;
{code:shell}
2022-07-31 03:17:44,009 main ERROR RollingRandomAccessFileManager
target/rolling-random-direct-switch-director/%d{s}/%d{s}.log Failed to create
file after rollover: java.io.FileNotFoundException:
target/rolling-random-direct-switch-director/44/44.log (No such file or
directory) java.io.FileNotFoundException:
target/rolling-random-direct-switch-director/44/44.log (No such file or
directory)
{code}
Apparently the directory has not been created when the file is creating
was:
If you want split the log into different directories by period (day, hour,
minute, etc.), and use
[RollingRandomAccessFileAppender|https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender]
with a [DirectWrite
rollover|https://logging.apache.org/log4j/2.x/manual/appenders.html#RolloverStrategies],
the config should be:
{code}
<RollingRandomAccessFile name="RollingFile"
filePattern="${baseDir}/%d{s}/%d{s}.log">
<PatternLayout header= "${LOG_HEADER}">
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
{code}
At that time when you create the first log of each directory, console shows;
{code:java}
2022-07-31 03:17:44,009 main ERROR RollingRandomAccessFileManager
target/rolling-random-direct-switch-director/%d{s}/%d{s}.log Failed to create
file after rollover: java.io.FileNotFoundException:
target/rolling-random-direct-switch-director/44/44.log (No such file or
directory) java.io.FileNotFoundException:
target/rolling-random-direct-switch-director/44/44.log (No such file or
directory) {code}
Apparently the directory has not been created when the file is creating
> RollingRandomAccessFileAppender with DirectWriteRolloverStrategy can't create
> the first log file of different directory
> ------------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-3565
> URL: https://issues.apache.org/jira/browse/LOG4J2-3565
> Project: Log4j 2
> Issue Type: Bug
> Reporter: su pei tao
> Priority: Major
>
> When you want split the log into different directories by period (day, hour,
> minute, etc.), and use
> [RollingRandomAccessFileAppender|https://logging.apache.org/log4j/2.x/manual/appenders.html#RollingRandomAccessFileAppender]
> with a [DirectWrite
> rollover|https://logging.apache.org/log4j/2.x/manual/appenders.html#RolloverStrategies],
> the config should be:
> {code:xml}
> <RollingRandomAccessFile name="RollingFile"
> filePattern="${baseDir}/%d{s}/%d{s}.log">
> <PatternLayout header= "${LOG_HEADER}">
> <Pattern>${LOG_PATTERN}</Pattern>
> </PatternLayout>
> <Policies>
> <TimeBasedTriggeringPolicy/>
> </Policies>
> </RollingRandomAccessFile>
> {code}
>
> At that time when you create the first log of each directory, console shows;
> {code:shell}
> 2022-07-31 03:17:44,009 main ERROR RollingRandomAccessFileManager
> target/rolling-random-direct-switch-director/%d{s}/%d{s}.log Failed to create
> file after rollover: java.io.FileNotFoundException:
> target/rolling-random-direct-switch-director/44/44.log (No such file or
> directory) java.io.FileNotFoundException:
> target/rolling-random-direct-switch-director/44/44.log (No such file or
> directory)
> {code}
> Apparently the directory has not been created when the file is creating
--
This message was sent by Atlassian Jira
(v8.20.10#820010)