弹簧启动弹簧.log在 tmp 下



我在测试期间使用/tmp/spring.log 文件

但这无济于事。我有一个登录.xml在我的 spring 启动应用程序中,当我启动它时,它会在 var/tmp/spring.log 中创建一个日志。现在这不能在客户端站点上工作。有没有办法将其配置为不创建它,我的日志已经将控制台记录在我在追加器中定义的日志文件中。我什至不知道这种情况正在发生。今年春天.log与滚动文件追加器一起使用,这意味着它每天都会继续创建日志。

我删除了:

<!--include resource="org/springframework/boot/logging/logback/base.xml"/-->

从我的登录中.xml但它仍然没有阻止它访问文件或创建它

任何帮助将不胜感激

编辑:我的登录.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/fix.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>90</maxHistory>
</rollingPolicy>
<encoder>
<charset>utf-8</charset>
<Pattern>%d %-5level [%thread] %logger{0}: %msg%n</Pattern>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>512</queueSize>
<appender-ref ref="FILE"/>
</appender>


<logger name="com.comp.myapp" level="INFO"/>

<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<root level="INFO">
<appender-ref ref="FILE" />
<!--<appender-ref ref="CONSOLE"/>-->
</root>

由此产生的问题是,如果我使用相同的用户部署了两次相同的应用程序。 两个应用程序都在写入同一个文件,这毫无意义。如果我在同一台机器上也部署了另一个 Spring 启动应用程序,它们将写入同一个 spring.log tmp 文件夹中。我不明白创建"偷偷摸摸"日志背后的原因是什么(我会称之为偷偷摸摸)

替换

<include resource="org/springframework/boot/logging/logback/base.xml"/>

<include resource="org/springframework/boot/logging/logback/defaults.xml" />

详情链接:-

https://github.com/spring-projects/spring-boot/issues/12538

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/base.xml

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml

添加

<include resource="org/springframework/boot/logging/logback/defaults.xml" />

确实很重要,但您最终想要的是您无需将日志保存到tmp即可获得的所有功能。如果您查看<include resource="org/springframework/boot/logging/logback/base.xml" />您会发现以下内容:

<included>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</included>

因此,您希望将<include resource="org/springframework/boot/logging/logback/base.xml" />替换为以下内容:

<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>

这样,您仍然可以像使用基本 xml 一样在 IDE 中查看日志。

最新更新