防止Spring Boot将日志打印到控制台 [英] Prevent Spring Boot from printing logs to console

查看:698
本文介绍了防止Spring Boot将日志打印到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为应用程序使用Spring Boot,并且正在使用默认的Spring Boot日志记录.

I am using spring boot for my application and I am using default spring boot logging.

在我的application.properties中,我添加了logging.file的文件路径,

In my application.properties, I have added file path for logging.file,

        logging.file= ${logger_path}

和我的pom.xml包含

       <logger_path>/tmp/app.log</logger_path>

启动应用程序时,它会将日志记录消息打印到/tmp/app.log处的文件中,但是问题是它还在控制台上打印了日志消息.当我指定log file时,我真的不明白为什么它要在控制台上打印(尽管正在将它们打印到指定文件).

When I start the application, it prints the logging messages to the file at /tmp/app.log, but the problem is it also prints the log messages on the console. I really don't understand why it is printing on console (though it is printing them to the specified file) when I have specified a log file.

是否有任何配置可以防止spring boot将日志消息打印到控制台?

Is there any configuration to prevent spring boot from printing the log messages to console?

推荐答案

Spring Boot带有内置的logback记录器,默认配置为打印到控制台.

Spring boot comes with build-in logback logger, which is configured to print to the console by default.

您需要覆盖logback配置(在类路径上提供您自己的logback.xml). 在此处--第66.1节

You need to overwrite the logback configuration (providing your own logback.xml on the classpath). This is described here - - section 66.1

如何禁用回溯日志记录,请阅读此处-

How to disable logback logging read here -

如您所见,您必须提供值OFF ...类似

as you can see you have to provide the value OFF...something like:

<configuration>
  <include resource="base.xml" />
   .
   .
  <property name="root.level.console" value="OFF" />
</configuration>

注意:请记住,此处的总体思路是最小化来自spring-boot的登录配置.目的是您提供自己的登录配置并完全覆盖现有的配置-例如提供仅配置了日志文件添加程序的自己的logback配置-这应该是您的常规方法.

Note: Keep in mind that the general idea here is that the logback configuration coming from spring-boot is minimal. The intention is that you provide your own logback configuration and completely overwrite the existing one - e.g. providing your own logback configuration with only log file-appender configured - this should be your general approach.

这篇关于防止Spring Boot将日志打印到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆