taylorThunderbolt opened a new issue, #2661:
URL: https://github.com/apache/logging-log4j2/issues/2661
## Description
Use new FileAppender(the `append` option is set to false, the 'fileName'
option is equivalent to previous FileAppender) to log rest messages after
logging some messages, the previous messages still exists in the log file.
This fact does not conform to the description in official documents: `When
true - the default, records will be appended to the end of the file. When set
to false, the file will be cleared before new records are written.`
## Configuration
**Version:** 2.23.1
**Operating system:** all
**JDK:** JDK17
## Logs
```
xxxxxxxx
xxxxxxxx
11111
11111
```
## Reproduction
log4j2.xml
```xml
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
</Console>
<File name="file" fileName="logs/run.log" append="true"/>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="file"/>
</Root>
</Loggers>
</Configuration>
```
a demo to reproduct the issue:
```java
public class Main {
private static final Logger LOG = LogManager.getLogger("logger");
public static void main(String[] args) {
LOG.info("xxxxxxxx");
LOG.info("xxxxxxxx");
LoggerContext context = (LoggerContext) LogManager.getContext(false);
LoggerConfig logger =
context.getConfiguration().getLoggerConfig("logger");
logger.removeAppender("file");
FileAppender appender =
FileAppender.newBuilder().withAppend(false).setName("file")
.withFileName("logs/run.log").build();
appender.start();
logger.addAppender(appender, Level.INFO, null);
context.updateLoggers();
// after using a new appender, i expect the log file to only contain
the following message.
LOG.info("11111");
LOG.info("11111");
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]