gpt4 book ai didi

带有 Logback + springProperty 的 Spring Boot

转载 作者:行者123 更新时间:2023-12-05 02:19:07 30 4
gpt4 key购买 nike

我已经根据 Spring Boot Documentation 配置了我的 logback-spring.xml .这是我的 logback-spring.xml 文件

<configuration>

<springProperty name="appName" source="spring.application.name" defaultValue="myLogFile" />

<property name="log.date" value="%d{yyyy-MM-dd}" />
<property name="log.path" value="/log" />
<property name="log.file" value="${appName}" />
<property name="log.live.path" value="${log.path}/${log.file}.log" />

<appender name="myLogAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.live.path}</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/archive/${log.file}.${log.date}.log.gz</fileNamePattern>
<maxHistory>1</maxHistory>
</rollingPolicy>
</appender>

<logger name="com.log.logback" level="INFO" />
<logger name="com.log.sample" level="INFO" />

<root level="ERROR">
<appender-ref ref="myLogAppender" />
</root>
</configuration>

应用程序属性

spring.application.name=mybootapp

当我启动我的 spring boot 应用程序时,我看到在 /log 下创建了 2 个目录路径是 myLogFilebootstrap .从日志中,我可以看到在 logback 可以访问 spring 属性之前创建了 bootstrap 目录。我不知道为什么要创建 bootstrap 目录。我在使用 <springProperty> 之前没有看到这个问题在 logback xml 中。我在这里缺少任何配置吗?我在网上找不到任何相关信息。

供引用的 Logback 日志。

15:54:02,085 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@610f7aa - URL [jar:file:/C:/projects/jars/logback-logging-17.2.2.INT.jar!/logback-spring.xml] is not of type file
15:54:02,132 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [jar:file:/C:/projects/jars/logback-logging-17.2.2.INT.jar!/logback-spring.xml]
15:54:02,132 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 5 minutes
15:54:02,132 |-WARN in Logger[org.springframework.core.env.PropertySourcesPropertyResolver] - No appenders present in context [default] for logger [org.springframework.core.env.PropertySourcesPropertyResolver].
15:54:02,274 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:54:02,274 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [myLogAppender]
15:54:02,305 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@867988177 - Will use gz compression
15:54:02,305 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@867988177 - Will use the pattern /log/archive/bootstrap.%d{yyyy-MM-dd}.log for the active file
15:54:02,305 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/log/archive/bootstrap.%d{yyyy-MM-dd}.log.gz'.
15:54:02,305 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:54:02,305 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Tue Apr 18 15:45:05 EDT 2017
15:54:02,320 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[myLogAppender] - Active log file name: /log/bootstrap.log
15:54:02,320 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[myLogAppender] - File property is set to [/log/bootstrap.log]
15:54:02,336 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.log.logback] to INFO
15:54:02,336 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@48e1f6c7 - Propagating INFO level on Logger[com.log.logback] onto the JUL framework
15:54:02,336 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.log.sample] to INFO
15:54:02,336 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@48e1f6c7 - Propagating INFO level on Logger[com.log.sample] onto the JUL framework
15:54:02,336 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
15:54:02,336 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@48e1f6c7 - Propagating ERROR level on Logger[ROOT] onto the JUL framework
15:54:02,336 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [myLogAppender] to Logger[ROOT]
15:54:02,336 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:54:02,336 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@26abb146 - Registering current configuration as safe fallback point
15:54:03,139 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@242aa8d9 - URL [jar:file:/C:/projects/jars/logback-logging-17.2.2.INT.jar!/logback-spring.xml] is not of type file
15:54:03,139 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [jar:file:/C:/projects/jars/logback-logging-17.2.2.INT.jar!/logback-spring.xml]
15:54:03,139 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 5 minutes
15:54:03,139 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:54:03,139 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [myLogAppender]
15:54:03,139 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@300604602 - Will use gz compression
15:54:03,139 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@300604602 - Will use the pattern /log/archive/mybootapp.%d{yyyy-MM-dd}.log for the active file
15:54:03,140 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/log/archive/mybootapp.%d{yyyy-MM-dd}.log.gz'.
15:54:03,140 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:54:03,140 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Tue Apr 18 15:53:03 EDT 2017
15:54:03,140 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[myLogAppender] - Active log file name: /log/mybootapp.log
15:54:03,140 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[myLogAppender] - File property is set to [/log/mybootapp.log]
15:54:03,140 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.log.logback] to INFO
15:54:03,140 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@1b065145 - Propagating INFO level on Logger[com.log.logback] onto the JUL framework
15:54:03,140 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.log.sample] to INFO
15:54:03,140 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@1b065145 - Propagating INFO level on Logger[com.log.sample] onto the JUL framework
15:54:03,140 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
15:54:03,140 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@1b065145 - Propagating ERROR level on Logger[ROOT] onto the JUL framework
15:54:03,140 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [myLogAppender] to Logger[ROOT]
15:54:03,140 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:54:03,140 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@45cff11c - Registering current configuration as safe fallback point

有人可以帮忙吗。

最佳答案

这可能是因为我刚刚更新到 1.5.18 但这似乎有效,我与你的唯一变化是添加了 scope="context"。这是我使用 GELF appender 完成的方法

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProperty scope="context" name="name" source="spring.application.name"/>

<appender name="gelf" class="de.appelgriepsch.logback.GelfAppender">
<server>192.168.1.113</server>
<includeSource>true</includeSource>
<includeMDC>true</includeMDC>
<includeLevelName>true</includeLevelName>
<additionalFields>name=${name}</additionalFields>
</appender>
<root>
<appender-ref ref="gelf"/>
</root>
</configuration>

关于带有 Logback + springProperty 的 Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43482050/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com