tomcat - spring boot 1.4 登录外部tomcat

标签 tomcat logging spring-boot

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

更新: 我添加了一个 logback-spring.xml,它在嵌入式 tomcat 上运行良好,但在外部运行良好(它不创建文件)

最佳答案

这是我项目中使用的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>

application.yml 文件中:

logging.file: "/var/logs/tomcat/application.log"

=====已编辑:

我还会在 logback 配置中使用 springProfile 来将本地运行的配置与生产环境中的运行分开;这样我就可以在开发期间在 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>

关于tomcat - spring boot 1.4 登录外部tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41333281/

相关文章:

java - 如何获取数据层的ServletContext对象?

java - 在 IntelliJ 中使用 cargo 在 tomcat 上启动本地调试应用程序

vb.net - 如何以编程方式确定 VB 应用程序日志的位置?

ubuntu - XDebug 无法打开远程调试文件 '/var/log/xdebug/xdebug.log'?

java - 如何获取序列化的tomcat HttpSession以重新填充spring SessionRegistry

Python 记录器不工作

ssl - Spring Boot SSL 无法获得任何响应

java - 如何在 @Configuration 类中 Autowiring Spring 注释的服务类?

springboot + webpack 开发服务器,重建后不会更改 localhost 捆绑文件

java - Jersey Web 应用程序未部署在 tomcat 上