Spring Boot 1.3.5 Tomcat 访问日志轮换 [英] Spring Boot 1.3.5 Tomcat Access Log Rotation
本文介绍了Spring Boot 1.3.5 Tomcat 访问日志轮换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个项目并使用 Spring Boot 1.3.5.RELEASE.
I am working on a project and using Spring Boot 1.3.5.RELEASE.
我按照 tomcat 文档启用了 Tomcat 访问日志并禁用了轮换,但访问日志仍然以日期为后缀并且正在轮换.有没有办法禁用tomcat访问日志轮换?
I have enabled Tomcat Access Log and disabled rotation as per tomcat documentation but access logs still have date as suffix and are rotating. If there a way to disable tomcat access log rotation?
server :
port : 80
tomcat :
accesslog :
enabled : true
pattern : common
directory : /logs/
prefix : access
suffix : .log
rotatable : false
推荐答案
我能够通过在代码中手动设置访问日志配置来解决它.SpringBoot 1.3.5 中似乎没有公开可旋转属性的设置器
I was able to solve it by manually setting access log config in code. Seems setters for rotatable property are not exposed in SpringBoot 1.3.5
import org.apache.catalina.valves.AccessLogValve;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Application implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
AccessLogValve accessLogValve = new AccessLogValve();
accessLogValve.setEnabled(true);
accessLogValve.setPattern("common");
accessLogValve.setDirectory("/log/");
accessLogValve.setPrefix("access");
accessLogValve.setSuffix(".log");
accessLogValve.setRotatable(false);
factory.addContextValves(accessLogValve);
}
}
}
这篇关于Spring Boot 1.3.5 Tomcat 访问日志轮换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文