Spring boot 1.4登录外部tomcat

M.R*_*R.M 5 logging tomcat spring-boot

我在外部tomcat上部署spring boot war文件时遇到了麻烦.问题是我使用默认日志记录I(只设置logging.file = custom.log属性).它在嵌入式tomcat的STS中运行良好; 但是,在外部tomcat上部署时,不会创建任何日志文件.

更新:我添加了一个logback-spring.xml,它在嵌入式tomcat上工作正常但在外部没有(它不创建文件)

Ton*_*Lxc 0

这是logback-spring.xml我的项目中使用的,它与外部 Tomcat 配合良好。

<configuration>
  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
  <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
  <root level="INFO">
    <appender-ref ref="FILE"/>
  </root>
</configuration>
Run Code Online (Sandbox Code Playgroud)

并在application.yml文件中:

logging.file: "/var/logs/tomcat/application.log"
Run Code Online (Sandbox Code Playgroud)

=====编辑:

我还会springProfile在 logback 配置中使用来将本地运行的配置与生产中运行的配置分开;这样我就可以在开发过程中在 IDE 控制台中获取日志:

<configuration>
  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

  <springProfile name="local">
    <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
  </springProfile>

  <springProfile name="prod">
    <include resource="org/springframework/boot/logging/logback/file-appender.xml" />
    <root level="INFO">
        <appender-ref ref="FILE"/>
    </root>
  </springProfile>

</configuration>
Run Code Online (Sandbox Code Playgroud)