如何在使用logback-spring.xml时保留Spring Boot的默认日志。

huangapple go评论82阅读模式
英文:

how to keep springboot default log when using logback-spring.xml

问题

春季引导默认日志大致如下所示:

2020-04-06 19:34:11.323  INFO 19308 --- [  restartedMain] o.apache.catalina.core.StandardService   : 正在启动服务 [Tomcat]
2020-04-06 19:34:11.323  INFO 19308 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : 正在启动Servlet引擎:[Apache Tomcat/9.0.30]
2020-04-06 19:34:11.424  INFO 19308 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : 正在初始化Spring嵌入式WebApplicationContext
2020-04-06 19:34:11.424  INFO 19308 --- [  restartedMain] o.s.web.context.ContextLoader            : 根WebApplicationContext:初始化

此外,我编写了一个logback-spring.xml文件,为我的应用程序设置了一些记录器和附加器。然而,当logback-spring.xml存在于“资源”目录中时,春季引导默认日志将会消失。而logback-spring.xml中只有一个<configuration>元素,没有任何子元素。

我阅读了关于Spring Boot日志记录部分的文档,并获取了file。但是我不知道如何使用它...我尝试将元素<property name="CONSOLE_LOG_PATTERN ...复制到我的logback-spring.xml文件中,并将其用作我的附加器的格式化程序,然后将附加器附加到<root>。但是它不能工作。

谢谢。

英文:

the springboot default log is something like following:

2020-04-06 19:34:11.323  INFO 19308 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-06 19:34:11.323  INFO 19308 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.30]
2020-04-06 19:34:11.424  INFO 19308 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-06 19:34:11.424  INFO 19308 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initializ

And I wrote a logback-spring.xml for setting some logger and appender for my application. However, when the logback-spring.xml exists in "resources" directory, the springboot default log will disappear. And there is only a &lt;configuration&gt; without any subelement in logback-spring.xml.

I have read the part of springboot document which is about logging and got the file. But I don't know how to use it...I tried to copy the element &lt;property name=&quot;CONSOLE_LOG_PATTERN ... into my logback-spring.xml and using it as the formatter of my appender, then attaching the appender to &lt;root&gt;. But it can't work.

Thanks.

答案1

得分: 0

你需要在你的logback-spring.xml文件中包含基本配置。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>

<configuration scan="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="your.application.package" level="DEBUG"/>  
</configuration>
英文:

You need to include the base configuration in your logback-spring.xm file.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE configuration&gt;

&lt;configuration scan=&quot;true&quot;&gt;
    &lt;include resource=&quot;org/springframework/boot/logging/logback/base.xml&quot;/&gt;
    &lt;logger name=&quot;your.application.package&quot; level=&quot;DEBUG&quot;/&gt;  
&lt;/configuration&gt;

huangapple
  • 本文由 发表于 2020年4月6日 19:44:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/61059031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定