带有LogBack的SpringBoot创建LOG_PATH_IS_UNDEFINED文件夹 [英] SpringBoot with LogBack creating LOG_PATH_IS_UNDEFINED folder

查看:79
本文介绍了带有LogBack的SpringBoot创建LOG_PATH_IS_UNDEFINED文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将SpringBoot与LogBack一起使用,并在yml文件中使用以下配置:

I am using SpringBoot with LogBack and using the below configuration in my yml file:

logging:
    path: C:/var/log/pincode

logging.path Spring环境变量被转移到LOG_PATH环境变量,并且日志文件被放置在正确的位置,但是在我的项目的根目录中也创建了一个名为LOG_PATH_IS_UNDEFINED的目录.

The logging.path Spring Environment Variable is transferred to the LOG_PATH Environment variable and the log file is placed at the correct place, but there is also a directory called LOG_PATH_IS_UNDEFINED created in the root directory of my project.

这似乎是由于SpringBoot使用其环境变量配置LogBack所用的阶段不同.

This seems to be caused by the different phase used by SpringBoot to configure LogBack with its Environment variables.

17:29:21,325 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
17:29:21,337 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern LOG_PATH_IS_UNDEFINED/catalina.out.%d{yyyy-MM-dd} for the active file
17:29:21,340 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'LOG_PATH_IS_UNDEFINED/catalina.out.%d{yyyy-MM-dd}'.
17:29:21,340 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
17:29:21,343 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Aug 11 17:24:07 BRT 2014
17:29:21,346 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - Active log file name: LOG_PATH_IS_UNDEFINED/catalina.out
17:29:21,346 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - File property is set to [LOG_PATH_IS_UNDEFINED/catalina.out]
...
17:29:21,358 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

然后,它再次开始配置登录,但是这次使用我设置的路径:

And then after that it start configuring logback again but this time using the path i set:

17:29:21,672 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
17:29:21,673 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
17:29:21,673 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern C:/var/log/pincode//catalina.out.%d{yyyy-MM-dd} for the active file
17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'C:/var/log/pincode//catalina.out.%d{yyyy-MM-dd}'.
17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
17:29:21,674 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Aug 11 17:29:21 BRT 2014
17:29:21,674 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - Active log file name: C:/var/log/pincode//catalina.out
17:29:21,674 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[serverConsole] - File property is set to [C:/var/log/pincode//catalina.out]
...
17:29:21,685 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

我的logback.xml

My logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/basic.xml" />
<property name="FILE_LOG_PATTERN"
    value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex" />

<appender name="serverConsole"
          class="ch.qos.logback.core.rolling.RollingFileAppender">
    <Append>true</Append>
    <File>${LOG_PATH}/catalina.out</File>
    <encoder>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/catalina.out.%d{yyyy-MM-dd}
        </fileNamePattern>
        <maxHistory>15</maxHistory>
    </rollingPolicy>
</appender>

<!-- Plain Text Rolling Appender -->
<appender name="server"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <Append>true</Append>
    <File>${LOG_PATH}/pincode.log</File>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>INFO</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>
    <encoder>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/pincode.log.%d{yyyy-MM-dd}
        </fileNamePattern>
        <maxHistory>15</maxHistory>
    </rollingPolicy>
</appender>

<!-- Plain Text Rolling Appender -->
<appender name="server-error"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <Append>true</Append>
    <File>${LOG_PATH}/pincode-error.log</File>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
        <level>ERROR</level>
        <onMatch>ACCEPT</onMatch>
        <onMismatch>DENY</onMismatch>
    </filter>
    <encoder>
        <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>${LOG_PATH}/pincode-error.log.%d{yyyy-MM-dd}
        </fileNamePattern>
        <maxHistory>15</maxHistory>
    </rollingPolicy>
</appender>

<logger name="com.app" level="INFO">
    <appender-ref ref="server" />
    <appender-ref ref="server-error" />
</logger>

<root level="INFO">
    <appender-ref ref="serverConsole" />
</root> 

如果我从项目中删除logback.xml文件,则不会创建该文件夹,因此在解析yml之前Spring正在加载xml?

If I remove my logback.xml file from the project it doesn't create the folder, so somewhere Spring is loading the xml before parsing the yml?

如何避免使用Logback创建此LOG_PATH_IS_UNDEFINED目录?

How can I avoid Logback to create this LOG_PATH_IS_UNDEFINED directory?

推荐答案

在您的情况下,LOG_PATH在启动时未定义.您应该改用${LOG_PATH:-.}请参见.

In your case LOG_PATH is not defined on startup. You should use ${LOG_PATH:-.} instead , See .

但是,如果在application.properties中定义logging.path,您将在.${logging.path}目录中看到两个日志文件.

But if you define logging.path in your application.properties you will see two log files in . and in ${logging.path} directory.

Logback初始化后设置Spring容器LOG_PATH ...据我所知,不支持Logback惰性文件创建.在这种情况下,您应该使用logback-spring.xml代替logback.xml.

Spring container set LOG_PATH after Logback initialization... Logback is not supported lazy file creation as far as I know. In this case you should use logback-spring.xml instead logback.xml.

这篇关于带有LogBack的SpringBoot创建LOG_PATH_IS_UNDEFINED文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆