How to configure location and name of tomcat access log in spring-boot?

I have a spring-boot application with the following configuration in application.yml

server: contextPath: /rti tomcat: access-log-enabled: true access-log-pattern: "%h %l %u %t \"%r\" %s %b %D" basedir: tomcat 

You will be asked to create an access log tomcat / logs / access_log.2015-02-02.txt.

I would like to be able to configure where the access log is created and what it is called; but after a long search I begin to think that this is impossible. Does anyone know how to achieve this?

Application logging works fine using logging and configuration in logback.xml

+1
source share
2 answers

You can use the EmbeddedServletContainerCustomizer interface to add a fully custom valve to your built-in tomcat. Here is what works for me:

 @Configuration public class WebConfig extends WebMvcConfigurerAdapter implements EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container; AccessLogValve accessLogValve = new AccessLogValve(); accessLogValve.setDirectory("/var/log/test"); accessLogValve.setPattern("common"); accessLogValve.setSuffix(".log"); factory.addContextValves(accessLogValve); } else { logger.error("WARNING! this customizer does not support your configured container"); } } } 
+6
source

Configuration in application.yml ( https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html ):

 server.tomcat.accesslog: # Enable access log: enabled: true # Directory in which log files are created. Can be relative to the tomcat base dir or absolute: directory: /var/log/test # Format pattern for access logs: # https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve pattern: '%h %l %u %t "%r" %s %b %D' # Log file name suffix: suffix: .log 
+5
source

Source: https://habr.com/ru/post/1258522/


All Articles