Xfel opened a new issue, #2020:
URL: https://github.com/apache/logging-log4j2/issues/2020

   ## 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:
   ```
   <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
   ```


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

Reply via email to