logging - How do you tell Spring Boot to send the embedded Tomcat's access logs to stdout? -
in standalone spring boot web application (executable jar), how tell spring boot want embedded tomcat instance's http access logs sent stdout?
if use logback, can use logback-access this.
add dependency ch.qos.logback:logback-access
optional javaconfig add teefilter (request & response logging):
@bean(name = "teefilter") public filter teefilter() { return new ch.qos.logback.access.servlet.teefilter(); }
javaconfig embedded tomcat:
@bean public embeddedservletcontainerfactory servletcontainer() { tomcatembeddedservletcontainerfactory tomcat = new tomcatembeddedservletcontainerfactory(); logbackvalve logbackvalve = new logbackvalve(); // point logback-access.xml logbackvalve.setfilename("src/main/resources/logback-access.xml"); tomcat.addcontextvalves(logbackvalve); return tomcat; }
contents logback-access.xml
<configuration> <appender name="stdout" class="ch.qos.logback.core.consoleappender"> <encoder> <pattern>combined</pattern> <pattern>%fullrequest%n%n%fullresponse</pattern> </encoder> </appender> <appender-ref ref="stdout" /> </configuration>
Comments
Post a Comment