禁用 /opt/engine.log 中的默认日志记录

问题描述 投票:0回答:1

我有一个带有许多子框架的 Spring Boot 应用程序。当我启动应用程序时,我默认登录

/opt/engine.log
。有没有办法全局禁用此日志记录?

spring spring-boot log4j
1个回答
0
投票

是的,您可以通过不同的方式重定向日志。

  1. 您可以在 .properties 文件中添加
    logging.file=/path/to/your/logfile.log
    或者在 yaml 文件中添加
    logging: file: /path/to/your/logfile.log
  2. 如果您的应用程序使用 logback,请添加到 logback.xml:
<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <property name="LOG_FILE" value="/path/to/your/logfile.log"/>
    <include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
    <root level="OFF">
        <appender-ref ref="FILE"/>
    </root>
</configuration>
  1. 如果您的应用程序使用 log4j2,请添加到 log4j2.xml:
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
        <File name="File" fileName="/path/to/your/logfile.log">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="OFF">
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
</Configuration>
© www.soinside.com 2019 - 2024. All rights reserved.