Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 323
quartaela Avatar asked Jul 10 '26 23:07

quartaela


1 Answers

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" />
like image 195
jaknichan Avatar answered Jul 13 '26 12:07

jaknichan