[英]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.我的 spring-boot 应用程序创建了一个名为
logging.path_IS_UNDEFINEDlogging.file_IS_UNDEFINED.log
的日志文件,其中明确指出在 logback 初始化日志配置时未设置logging.path
和logging.file
属性。 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
我正在使用 spring-boot 2.0 版
application-dev.yaml应用程序-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 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 :或者,您可以在 logback.xml 中设置一个“路径”变量并将文件名附加到它以将其存储在另一个“LOG_FILE”属性中:
<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.
因此,当我更新Spring Boot 版本 (2.4.1)并开始收到 LOG_PATH_IS_UNDEFINED 错误时,我提出了类似的问题。
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.我做了一些研究,我猜测从 logging.path 到 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:我在最顶部的 logback-spring.xml 中添加了一个手动映射:
<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 .你在application-dev.yaml 中初始化的 logging.path 在spring-logback.xml 中设置了变量${LOG_PATH} 。
if you initialize variable logging.file , you can use variable ${LOG_FILE} in spring-logback.xml so you should initialize like below.如果你初始化变量logging.file ,你可以在spring-logback.xml 中使用变量${LOG_FILE}所以你应该像下面那样初始化。
logging:
file: /var/logs/myApp.log
and set variable in spring-logback.xml并在spring-logback.xml 中设置变量
<property name="LOG_FILE" value="${LOG_FILE}"/>
<file>${LOG_FILE}</file>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.