Gwy*_*sen 2 tomcat logback spring-boot
我有一个spring-boot应用程序,在application.yml中具有以下配置
server:
contextPath: /rti
tomcat:
access-log-enabled: true
access-log-pattern: "%h %l %u %t \"%r\" %s %b %D"
basedir: tomcat
Run Code Online (Sandbox Code Playgroud)
这会提示创建访问日志tomcat/logs/access_log.2015-02-12.txt.
我希望能够配置创建访问日志的位置和命名内容; 但经过多次搜索,我开始认为这是不可能的.有谁知道如何实现这一目标?
应用程序日志记录在logback.xml中使用logback和配置正常工作
配置使用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"
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用EmbeddedServletContainerCustomizer接口向嵌入式tomcat添加完全自定义的阀门.这对我有用:
@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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11907 次 |
| 最近记录: |