英文:
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 <configuration>
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 <property name="CONSOLE_LOG_PATTERN ...
into my logback-spring.xml and using it as the formatter of my appender, then attaching the appender to <root>
. 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.
<?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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论