Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectWriteRolloverStrategy can't create log files on Windows Log4j2 2.17.2 #1645

Closed
posuhov opened this issue Jul 31, 2023 · 4 comments · Fixed by #2114
Closed

DirectWriteRolloverStrategy can't create log files on Windows Log4j2 2.17.2 #1645

posuhov opened this issue Jul 31, 2023 · 4 comments · Fixed by #2114
Assignees
Labels
appenders Affects one or more Appender plugins bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment
Milestone

Comments

@posuhov
Copy link

posuhov commented Jul 31, 2023

Description

My application is running on SpringBoot 2.7.13. I have an appender defined like

Configuration:
  status: warn
  appenders:
    RollingFile:
      - name: LogToRollingFileWithPattern
        filePattern: application-%i.log
        PatternLayout:
          Pattern: "%level %d{DEFAULT_MICROS} [%t] %c{1} %X{AWS-XRAY-TRACE-ID} - %msg%n"
        Policies:
          SizeBasedTriggeringPolicy:
            size: 1MB
        DirectWriteRolloverStrategy:
          maxFiles: 5
  Loggers:
    Root:
      level: info
      AppenderRef:
        - ref: LogToRollingFileWithPattern

Once I start the application the exception is printed in console and file are not created.
Everything works with DefaultRolloverStrategy and files are created as expected

Configuration

Version: 2.17.2

Operating system: Windows 10

JDK: JDK 17

Logs

2023-07-31 18:35:38,086 main ERROR An exception occurred processing Appender LogToRollingFileWithPattern java.lang.NullPointerException: Cannot invoke "java.io.File.mkdirs()" because the return value of "java.io.File.getParentFile()" is null
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.createParentDir(RollingFileManager.java:253)
	at org.apache.logging.log4j.core.appender.FileManager.createOutputStream(FileManager.java:191)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.getOutputStream(OutputStreamManager.java:165)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.writeToDestination(OutputStreamManager.java:250)
	at org.apache.logging.log4j.core.appender.FileManager.writeToDestination(FileManager.java:277)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.writeToDestination(RollingFileManager.java:275)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.flushBuffer(OutputStreamManager.java:283)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:294)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:217)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:208)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:199)
	at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:312)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:161)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:134)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:675)
	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:633)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
	at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:666)
	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:635)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:552)
	at org.apache.logging.log4j.core.config.DefaultReliabilityStrategy.log(DefaultReliabilityStrategy.java:63)
	at org.apache.logging.log4j.core.Logger.log(Logger.java:161)
	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2022)
	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1875)
	at org.apache.commons.logging.LogAdapter$Log4jLog.log(LogAdapter.java:266)
	at org.apache.commons.logging.LogAdapter$Log4jLog.info(LogAdapter.java:230)
	at org.springframework.boot.SpringApplication.logStartupProfileInfo(SpringApplication.java:637)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:378)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at com.example.Application.main(Application.java:21)

Reproduction

Errors appears right after application start. It happens during creation a directory for logs
image
However if we replace file.getParentFile() with file.getAbsoluteFile().getParentFile() it returns a correct non null File

@rgoers rgoers self-assigned this Jul 31, 2023
@jvz jvz added bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment appenders Affects one or more Appender plugins labels Oct 15, 2023
@posuhov
Copy link
Author

posuhov commented Nov 14, 2023

is there any ETA on this?

@ppkarwasz
Copy link
Contributor

@posuhov,

Is it still reproducible in version 2.21.1?

@posuhov
Copy link
Author

posuhov commented Nov 20, 2023

@ppkarwasz yes, exception the same with 2.21.1

An exception occurred processing Appender LogToRollingFileWithPattern
 java.lang.NullPointerException: Cannot invoke "java.io.File.mkdirs()" because the return value of "java.io.File.getParentFile()" is null
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.createParentDir(RollingFileManager.java:253)
	at org.apache.logging.log4j.core.appender.FileManager.createOutputStream(FileManager.java:192)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.getOutputStream(OutputStreamManager.java:165)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.writeToDestination(OutputStreamManager.java:250)
	at org.apache.logging.log4j.core.appender.FileManager.writeToDestination(FileManager.java:278)
	at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.writeToDestination(RollingFileManager.java:275)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.flushBuffer(OutputStreamManager.java:283)
	at org.apache.logging.log4j.core.appender.OutputStreamManager.flush(OutputStreamManager.java:294)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:221)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:212)
	at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:203)
	at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:301)
	at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:161)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:134)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
	at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
	at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:686)
	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:644)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:620)
	at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:677)
	at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:646)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:620)
	at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:556)
	at org.apache.logging.log4j.core.config.DefaultReliabilityStrategy.log(DefaultReliabilityStrategy.java:62)
	at org.apache.logging.log4j.core.Logger.log(Logger.java:163)
	at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2165)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2119)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2102)
	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1954)
	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1812)
	at org.apache.commons.logging.LogAdapter$Log4jLog.log(LogAdapter.java:270)
	at org.apache.commons.logging.LogAdapter$Log4jLog.info(LogAdapter.java:230)
	at org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:55)
	at org.springframework.boot.SpringApplication.logStartupInfo(SpringApplication.java:615)
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:377)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at com.example.Application.main(Application.java:21)

@ppkarwasz ppkarwasz self-assigned this Nov 20, 2023
@ppkarwasz
Copy link
Contributor

ppkarwasz commented Nov 29, 2023

@posuhov,

Thank you for the report. This is clearly a bug that we'll fix in the next release.

In the mean time, you can work around it by using an absolute path in filePattern or something like logs/application-%i.log.

@ppkarwasz ppkarwasz added this to the 2.22.1 milestone Nov 29, 2023
ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Dec 20, 2023
This PR fixes a `NullPointerException` in
`RollingFileManager#createParentDir`.

Closes apache#1645
ppkarwasz added a commit that referenced this issue Dec 21, 2023
This PR fixes a `NullPointerException` in
`RollingFileManager#createParentDir`.

Closes #1645
dongjoon-hyun pushed a commit to apache/spark that referenced this issue Jan 11, 2024
### What changes were proposed in this pull request?
This pr aims to upgrade log4j2 from 2.22.0 to 2.22.1.

### Why are the changes needed?
The new version contains some bug fixes:
- [Fix NPE in CloseableThreadContext](apache/logging-log4j2#1426)
- [Fix NPE in RollingFileManager](apache/logging-log4j2#1645)

And 2.22.1 is generated using JDK 17, the full release note as follows:
- https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.22.1

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #44682 from LuciferYang/SPARK-46672.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appenders Affects one or more Appender plugins bug Incorrect, unexpected, or unintended behavior of existing code runtime Specific to the runtime environment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants