phanindra798 opened a new pull request, #4473: URL: https://github.com/apache/logging-log4j2/pull/4473
Fixes #3083. Adds the `createOnDemand` attribute to `RandomAccessFileAppender`, `RollingRandomAccessFileAppender` and `MemoryMappedFileAppender`, so that all five file appenders support it. This follows the approach suggested by @ramanathan1504 in the issue. When `createOnDemand` is `true`, the file and its parent directories are only created on the first write. With `append="false"`, an existing file is kept until the first event and emptied then. In the managers a `null` `RandomAccessFile` means the file is not open yet: * `RollingRandomAccessFileManager`: already opens the file on `null` in `writeToDestination()`. The startup open and `defineAttributeView` are skipped, and the parameter is added to the unreleased `maxRandomDelay` overload. No new constructor. * `RandomAccessFileManager`: opens the file on `null` in `writeToDestination()`, with a `null` check in `closeOutputStream()`. No new constructor. A new `getFileManager` overload takes `createOnDemand`, because the existing one is already released. * `MemoryMappedFileManager`: `byteBuffer` stays empty until the first write, and the file is opened and mapped in `remap()`. There is no new check in `write`. This uses one new private constructor and a new `getFileManager` overload. Tests for each of the three appenders cover: no file before the first event, no events at all, `append="false"` with a longer old file, appending to an existing file, and the default eager creation. The attribute is also documented in `file.adoc`. ## Checklist * [x] Changes are based on the `2.x` branch * [ ] `./mvnw verify` succeeds: I ran the appender tests of `log4j-core-test` locally, but not the full build, so I am relying on CI for that * [x] A changelog entry is added in `src/changelog/.2.x.x` * [x] Tests are provided I worked on this change with assistance from Claude for the implementation and tests, following the approach agreed in the issue. -- 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]
