2017-07-12 107 views

回答

1

您必须在类路径的根目录(通常在src/main/resources)中定义logback.xml文件。

例子:

<?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项目的根目录)。

查看SpringLogback文档以获取更多详细信息。

0

只是这行添加到您的application.yaml(或等值application.properties)

logging: 
    file: directorname/nameoflogfile.log 

春季启动将处理其余部分。我不认为你明确地需要添加一个logback.xml文件,因为无论如何都有一个在classpath中发布。

相关问题