最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - java.io.IOException: Could not create directory in Log4j2 - but logging works - Stack Overflow

programmeradmin7浏览0评论

I have an issue occurring on my client's MF environment, where the logging seems to work correctly:

  • Log files are created if they don't exist and updated if they need to be.
  • The log folder is also created or updated as needed.

However, error messages are being generated, and I can't figure out why.

I tried to reproduce the issue on my own system, but I didn't succeed yet.

According to the client, there are no permission issues and the PROJ_HOME is correctly defined.

These are the error messages my client is receiving:

JVMJZBL1023N Invoking .springframework.boot.loader.launch.JarLauncher.main()...
JVMJZBL1024N .springframework.boot.loader.launch.JarLauncher.main() completed.
ERROR StatusConsoleListener Unable to create file ${PROJ_HOME}/logs/app.log
java.io.IOException: Could not create directory /${PROJ_HOME}/logs
    at .apache.logging.log4j.core.util.FileUtils.mkdir(FileUtils.java:128)
    at .apache.logging.log4j.core.util.FileUtils.makeParentDirs(FileUtils.java:141)
.....
ERROR StatusConsoleListener Could not create plugin of type class .apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile:
java.lang.IllegalStateException: ManagerFactory [.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory@ec0d2afb] unable to create manager for [${PROJ_HOME}/logs/app.log] with data [.apache.logging.log4j.core.appender.rolling.RollingFileManager$FactoryData@f353a58e[pattern=${PROJ_HOME}/logs/app.%i.log, append=true, bufferedIO=true, bufferSize=8192, policy=CompositeTriggeringPolicy(policies=[SizeBasedTriggeringPolicy(size=5242880)]), strategy=DefaultRolloverStrategy(min=1, max=20, useMax=true), advertiseURI=null, layout=%d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c{1.}] - %msg%n, filePermissions=null, fileOwner=null]]
....
ERROR StatusConsoleListener Null object returned for RollingFile in Appenders.
ERROR StatusConsoleListener Null object returned for RollingFile in Appenders.
ERROR StatusConsoleListener Unable to locate appender "AppRollingFile" for logger config "root"
ERROR StatusConsoleListener Unable to locate appender "AppRollingFile" for logger config "com.example.app"

Maybe the system is trying to create the folder again, even though it already exists, which might explain why the first error is 'Could not create directory.' Maybe someone is familiar with this issue?

This is the log4j.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <property name="LOG_FILE">${env:PROJ_HOME}/logs</property>
        <property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c{1.}] - %msg%n</property>
    </Properties>
    <Appenders>
        <RollingFile
                name="AppRollingFile"
                fileName="${LOG_FILE}/application.log"
                filePattern="${LOG_FILE}/application.%i.log"
                ignoreExceptions="false">
            <PatternLayout>
                <Pattern>${LOG_PATTERN}</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="5MB" />
            </Policies>
            <DefaultRolloverStrategy max="20" />
        </RollingFile>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout>
                <Pattern>${LOG_PATTERN}</Pattern>
            </PatternLayout>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="AppRollingFile"/>
            <AppenderRef ref="Console"/>
        </Root>
        <logger name="com.example.app" level="INFO" additivity="false">
            <AppenderRef ref="AppRollingFile"/>
            <AppenderRef ref="Console"/>
        </logger>
    </Loggers>
</Configuration>

I would appreciate any ideas or suggestions.

Thanks!

发布评论

评论列表(0)

  1. 暂无评论