0

I am working on a project and using Spring Boot 1.3.5.RELEASE.

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
SSingla
  • 21
  • 4

1 Answers1

0

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);
        }
    }
}
SSingla
  • 21
  • 4