Last active
July 23, 2021 23:05
-
-
Save nathansgreen/305ddf9e492ab69c027cb289f6dfa643 to your computer and use it in GitHub Desktop.
Send Embedded Tomcat Access Logs to Application Logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@lombok.extern.log4j.Log4j2 | |
public class AccessLogValve extends | |
org.apache.catalina.valves.AbstractAccessLogValve { | |
@Override | |
protected void log(java.io.CharArrayWriter message) { | |
log.info(message.toString()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class SpringConfig { | |
@Bean | |
@ConfigurationProperties(prefix = "server.tomcat.accesslog") // .pattern is required | |
public AccessLogValve accessLogValve() { | |
return new AccessLogValve(); | |
} | |
@Bean | |
public WebServerFactoryCustomizer<ConfigurableTomcatWebServerFactory> containerCustomizer() { | |
return factory -> factory.addEngineValves(accessLogValve()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment