简体   繁体   中英

spring-boot creates logging.path_IS_UNDEFINED.log file

my spring-boot application creates a log file with name logging.path_IS_UNDEFINEDlogging.file_IS_UNDEFINED.log which clearly states that logging.path and logging.file properties are not set while logback is initializing log configuration. This sounds like a duplicate of this one However, I tried all the suggested solutions from that post. I am using spring-boot version 2.0

application-dev.yaml

spring:
  main:
    allow-bean-definition-overriding: true
  application:
    name: my-application

logging:
  path: /var/logs/${spring.application.name}/
  file:
    max-size: 10MB
    max-history: 5

spring-logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/file-appender.xml"/>

    <property name="logging.pattern.console" value="%d{HH:mm:ss.SSS} [%t] %-5level %X{transactionId} %logger{36} - %msg%n"/>
    <property name="logging.file.roll-pattern" value="application-%d{yyyy-MM-dd}-%i.log"/>

    <springProfile name="dev">
        <property resource="application-dev.yaml" />
        <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
        <logger name="org.springframework" level="INFO"/>
        <logger name="com.myapp" level="DEBUG"/>

        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${logging.path}${logging.file}.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- daily rollover -->
                <fileNamePattern>${logging.path}${logging.file}.%d{yyyy-MM-dd}.log</fileNamePattern>

                <!-- keep 30 days' worth of history capped at 3GB total size -->
                <maxHistory>30</maxHistory>
                <totalSizeCap>3GB</totalSizeCap>

            </rollingPolicy>

            <encoder>
                <pattern>${FILE_LOG_PATTERN}</pattern>
            </encoder>
        </appender>

        <root level="INFO">
            <appender-ref ref="CONSOLE"/>
            <appender-ref ref="FILE"/>
        </root>
    </springProfile>
</Configuration>

Altenratively, you can set a "path" variable in your logback.xml and append to it your filename to store it in another "LOG_FILE" property :

    <springProperty scope="context" name="path" 
    source="logging.path" />
<property name="LOG_FILE" 
    value="${path}/myapp.log" />

Happy new year everybody! So, I came up with a similar issue when I've updated the spring boot version (2.4.1) and I started getting the LOG_PATH_IS_UNDEFINED error.

I did a bit of research and I'm guessing there is a problem with the mapping of the properties from logging.path to LOG_PATH. (I manually debugged the logger and the properties were being load)

My solution/Patch:

I added a manual mapping to the logback-spring.xml at the very top:

<springProperty scope="context" name="LOG_PATH" source="logging.path"/>

Now it is working for me...

logging.path you initialized in application-dev.yaml set variable ${LOG_PATH} in spring-logback.xml .

if you initialize variable logging.file , you can use variable ${LOG_FILE} in spring-logback.xml so you should initialize like below.

logging:
    file: /var/logs/myApp.log

and set variable in spring-logback.xml

<property name="LOG_FILE" value="${LOG_FILE}"/>
<file>${LOG_FILE}</file>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM