【springboot系】springboot内嵌tomcat配置Accesslog日志文件保留天数

现在SpringBoot应用大多是内嵌tomcat,以jar包方式启动对外提供服务

有些时候一些老的项目我们需要开启tomcat服务器访问日志,想看一下服务器记录的访问站点活动(点击,页面浏览,状态错误码)这些可能有用的记录来分析某些原因或者统计某一个请求的数量。当然这些我们也可以直接在nginx上面来捕捉到

那如何开启对应的accesslog日志配置呢,默认tomcat是禁用的

我们可以根据官网找到对应的资料

Spring Boot Reference Documentation

17.3.11. Configure Access Logging

Access logs can be configured for Tomcat, Undertow, and Jetty through their respective namespaces.

For instance, the following settings log access on Tomcat with a custom pattern.

点击上述 custom pattern就可以到对应tomcat的文档

具体源码配置位置在

org.springframework.boot.autoconfigure.web.ServerProperties$Tomcat$Accesslog

里面我们可以看到对应的有个属性maxDays这个默认值-1,代表永久保留。我们就可以设置这个值

来调整保留天数为15天

server.tomcat.accesslog.maxDays=15

springboot项目开启accesslog日志的完整配置如下

server.tomcat.basedir=./

server.tomcat.accesslog.enabled=true

server.tomcat.accesslog.directory=./logs/

server.tomcat.accesslog.prefix=access

server.tomcat.accesslog.maxDays=15

server.tomcat.accesslog.pattern=%{yyyyMMddHHmmssSSS}t|%a|%h|%H|%r|%{Referer}i|%s|%b|%D|%s

猜你喜欢

转载自blog.csdn.net/run_boy_2022/article/details/131727491
今日推荐