我在外部tomcat上部署spring引導war文件時遇到了問題。問題是我使用默認日誌記錄I(只需設置logging.file = custom.log屬性)。它在嵌入式tomcat的STS內運行良好;但是,在外部tomcat上部署時,不會創建日誌文件。Spring引導1.4登錄外部tomcat
更新: 我添加了的logback-spring.xml,它工作正常嵌入式的Tomcat而不是外部(它不會創建該文件)
我在外部tomcat上部署spring引導war文件時遇到了問題。問題是我使用默認日誌記錄I(只需設置logging.file = custom.log屬性)。它在嵌入式tomcat的STS內運行良好;但是,在外部tomcat上部署時,不會創建日誌文件。Spring引導1.4登錄外部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"
=====編輯:
我也將使用springProfile
的logback中配置的CONFIGS從生產運行本地運行的分離;
<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>
是否遵循在enter link description here例如中描述的步驟:這樣我可以在開發過程中得到IDE的控制檯日誌讓你的Application類擴展SpringBootServletInitializer?
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
你解決了嗎? – powder366
請參閱https://stackoverflow.com/questions/41333281/spring-boot-1-4-logging-on-external-tomcat/47407781#47407781也許它有幫助 – hans