Disable default logging in /opt/engine.log

31 Views Asked by At

I have a Spring Boot app with many sub frameworks. When I start the app I get by default logging in /opt/engine.log. Is there some way to disable globally this logging?

1

There are 1 best solutions below

2
Pablo Aragonés On BEST ANSWER

Yes, you can redirect the log in different ways.

  1. You can add in the .properties file logging.file=/path/to/your/logfile.log or, in the yaml file logging: file: /path/to/your/logfile.log
  2. If your application uses logback, add to 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. If your application uses log4j2, add to 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>

UPDATED:

You can set the root logger level to OFF or ERROR to disable logging. For that you can modify your logback.yml file.

logger:
    - name: ROOT
      level: OFF

And also you can disable logging for a specific appender

appender:
    - name: FILE
      enabled: false