如何在外部日志文件中的Spring Boot中应用日志记录? [英] how to apply logging in spring boot in external log file?
本文介绍了如何在外部日志文件中的Spring Boot中应用日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Spring Boot项目中将日志记录应用到外部文件中.是否有可能.我已经追踪了许多网站.请帮忙.
I am trying to apply logging in external file in my spring boot project. Is it possible. I have followed many websites. Please help.
推荐答案
您必须在类路径的根目录(通常在src/main/resources
中)定义一个logback.xml
文件.
You have to define a logback.xml
file at the root of the classpath (typically in src/main/resources
).
示例:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs.log</file>
<append>true</append>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework.web" level="DEBUG" />
<logger name="your.custom.package" level="TRACE" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
此配置将创建一个logs.log
文件(在您的Maven项目的根目录中).
This configuration creates a logs.log
file (at the root of your Maven project).
Check the Spring and Logback documentations to get more details.
这篇关于如何在外部日志文件中的Spring Boot中应用日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文