You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RandomAccessFileAppender does not write the header configured in the layout to the output file.
Configuration
Version: 2.22.0
Operating system: Windows 10
JDK: Temurin 11.0.16.1
Reproduction
Using the following log4j2.xml:
<Configuration>
<Properties>
<!-- the pattern we use for our log files -->
<Property name="DefaultPattern">%d{DEFAULT} [%-5p] %c{1} - %m%n</Property>
<!-- a header written of the beginning of every log file -->
<Property name="DefaultHeader">*** HEADER ***${sys:line.separator}</Property>
</Properties>
<Appenders>
<File name="file" fileName="file.log" append="false">
<PatternLayout header="${DefaultHeader}" pattern="${DefaultPattern}" />
</File>
<RandomAccessFile name="randomaccessfile" fileName="randomaccessfile.log" append="false">
<PatternLayout header="${DefaultHeader}" pattern="${DefaultPattern}" />
</RandomAccessFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="file" />
<AppenderRef ref="randomaccessfile" />
</Root>
</Loggers>
</Configuration>
Combined with a simple program that just logs something, ie:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Test {
private static final Logger LOG = LogManager.getLogger();
public static void main(String[] args) {
LOG.info("Test");
}
}
This creates two files. The file.log is as expected:
*** HEADER ***
2023-11-30 16:54:04,898 [INFO ] Test - Test
But randomaccessfile.log does not contain the header line:
2023-11-30 16:54:04,898 [INFO ] Test - Test
The text was updated successfully, but these errors were encountered:
Description
RandomAccessFileAppender does not write the header configured in the layout to the output file.
Configuration
Version: 2.22.0
Operating system: Windows 10
JDK: Temurin 11.0.16.1
Reproduction
Using the following log4j2.xml:
Combined with a simple program that just logs something, ie:
This creates two files. The file.log is as expected:
But randomaccessfile.log does not contain the header line:
The text was updated successfully, but these errors were encountered: