membersound
membersound

Reputation: 86747

How to disable console logging in spring-boot?

I'm using the default logging configuration of spring-boot.

How can I prevent the console output, while keeping the logging into a logfile configured with logging.file=myfile.log?

My goal is to not having console windows output, but only logging to that file.

Without having to create a specific logback.xml configuration. Because I'm using spring-boot for not having to configure the logging myself.

Upvotes: 19

Views: 42298

Answers (4)

Ranjan Singh
Ranjan Singh

Reputation: 39

  1. Create a file logback-spring.xml in /resources/ folder of your application.
  2. Copy the below content in logback-spring.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<configuration>
    <appender name = "STDOUT" class = "ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%m%n</pattern>
        </encoder>
    </appender>
    <root level = "INFO">
        <appender-ref ref = "STDOUT"/>
    </root>
</configuration>

Upvotes: 2

membersound
membersound

Reputation: 86747

It turned out if I set the following property empty, the console logging is disabled:

logging.pattern.console=

Or commenting in xml if you use it

  <!--<root level="error">-->
        <!--<appender-ref ref="console"/>-->
    <!--</root>-->

Upvotes: 32

Jackson Cassimiro
Jackson Cassimiro

Reputation: 527

I created a file called logback.xml with the content:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml" />
    <logger name="org.springframework" level="ERROR"/>
    <logger name="org.hibernate" level="ERROR"/>
</configuration>

See this link for more information: https://www.mkyong.com/spring-boot/spring-boot-test-how-to-stop-debug-logs/

Upvotes: 2

dtenreiro
dtenreiro

Reputation: 168

All the supported logging systems can have the logger levels set in the Spring Environment using ‘logging.level.*=LEVEL’ where ‘LEVEL’ is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. The root logger can be configured using logging.level.root. Example application.properties:

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

Check this information: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html

You could also overwrite the logback configuration and provide the value OFF to it.

<configuration>
  <!-- turn OFF all logging (children can override) -->
  <root level="OFF">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

You can find more information at the following link: https://logback.qos.ch/manual/configuration.html#rootElement

Upvotes: -1

Related Questions