背景:在tomcat的access中打印出请求的情况可以帮助我们分析问题,通常比较关注的有访问IP、线程号、访问url、返回状态码、访问时间、持续时间。

在Spring boot中使用了内嵌的tomcat,可以通过server.tomcat.accesslog配置tomcat 的access日志

tomcat的accesslog日志

server.tomcat.accesslog.buffered=true
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
server.tomcat.accesslog.pattern=%a %h %m %l %u %t %r %s %S %b %D %T %I
server.tomcat.accesslog.prefix=access_log
server.tomcat.accesslog.rename-on-rotate=false
server.tomcat.accesslog.request-attributes-enabled=false
server.tomcat.accesslog.rotate=true
server.tomcat.accesslog.suffix=.log
server.tomcat.accesslog.directory=tomcat-access-logs

比较常用的有(省略了前缀server.tomcat.accesslog.):

  • enabled,取值true、false,需要accesslog时设置为true
  • directory,指定access文件的路径
  • pattern,定义日志的格式,后续详述
  • rotate,指定是否启用日志轮转。默认为true。这个参数决定是否需要切换切换日志文件,如果被设置为false,则日志文件不会切换,即所有文件打到同一个日志文件中,并且file-date-format参数也会被忽略

tomcat日志路径

server.tomcat.basedir=D:/logs(例)

主要字段:
server.tomcat.accesslog.pattern 解释:

%a - Remote IP address 远程IP地址
%A - Local IP address 本地IP地址
%b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent 返回给客户端的数据字节数,- 表示没有数据
%B - Bytes sent, excluding HTTP headers 与上面一样,貌似是官方的bug,应该是一个包含 HTTP headers 一个不包含
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method
%p - Local port
%q - Query string (prepended with a '?' if it exists, otherwise an empty string
%r - First line of the request
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format format
%u - Remote user that was authenticated
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis 处理请求耗时,单位毫秒
%T - Time taken to process the request, in seconds 同上,单位秒
%I - current Request thread name (can compare later with stacktraces) 执行当前请求的线程名称,输出可以统计多少线程在工作。

Access log 也支持将cookie、header、session或者其他在ServletRequest中的对象信息打印到日志中,其配置遵循Apache配置的格式({xxx}指值的名称):

%{xxx}i for incoming headers,request header信息
%{xxx}o for outgoing response headers,response header信息
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
%{xxx}t xxx is an enhanced SimpleDateFormat pattern (see Configuration Reference document for details on supported time patterns)

参考文章:https://blog.csdn.net/hrbeuwhw/article/details/81704549

https://blog.csdn.net/u013732378/article/details/100151205

Springboot项目中配置tomcta监控日志相关推荐

  1. 如何在Spring-Boot项目中配置资源文件夹?视频文件不想放在项目中,怎么做?前台上传文件后台如何访问?什么是资源文件夹?

    如何在Spring-boot项目配置资源文件夹 前言 2.properties文件 二.访问 1.放入资源 2.访问 方式1 方式2 前言 在什么情况下需要配置资源文件夹? 当项目需要读取静态文件夹以 ...

  2. 在springboot项目中配置hive-jdbc的maven依赖时遇到:Could not find artifact org.glassfish:javax.el:pom:3.0.1-b06-S

    解决方案 在配置时依赖时排除javax.el <dependency>     <groupId>org.apache.hive</groupId>     < ...

  3. 在maven web项目中配置log4j打印日志及Mybatis sql语句

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wei542657623/article/details/51591736 1 添加依赖 在pom.x ...

  4. SpringBoot项目中ModelMapper配置以及使用

    项目中对象与对象赋值转换使用的频率非常的高,比如数据库表实体对象(Entity)与业务类对象(Model)之间的赋值传递,或者模型对象(Model)与视图对象(ViewModel)之间的赋值传递.如果 ...

  5. springboot项目中利用@WebFilter注解和@Bean配置类两种方式实现Filter过滤器

    过滤器(Filter) 过滤器实际上就是对web资源进行拦截,做一些处理后再交给下一个过滤器或servlet处理.通常都是用来拦截request进行处理的,也可以对返回的response进行拦截处理 ...

  6. SpringBoot项目端点配置

    端点配置 开启端点 在SpringBoot中开启应用监控非常容易,只需要添加spring-boot-starter-actuator依赖即可,actuator(执行器)是制造业术语, 指一个用于移动或 ...

  7. SpringBoot 项目中集成 Prometheus 和 Grafana

    项目上线后,除了能保障正常运行以外,也需要服务运行的各个指标进行监控,例如 服务器CPU.内存使用占比,Full GC 执行时间等,针对一些指标出现异常,可以加入一些报警机制能及时反馈给开发运维.这样 ...

  8. SpringBoot项目中遇到的BUG

    1.启动项目的时候报错 1.Error starting ApplicationContext. To display the auto-configuration report re-run you ...

  9. SpringBoot项目中集成第三方登录功能

    SpringBoot项目中集成第三方登录功能 引言 1 环境准备 2 代码实现 3 第三方平台认证申请 4 打包和部署项目 5 第三方平台登录认证测试 6 参考文章 引言 最近想把自己在公众号上介绍过 ...

最新文章

  1. 病毒进入体内的48小时
  2. 单例模式 - 深究剖析
  3. OpenCV图像数据访问,查询表和时间消耗测试
  4. css层叠上下文详解,CSS定位(层叠上下文)
  5. mysql linux err2003_远程连接linux下的mysql Err1045 Err2003解决办法
  6. pythonencode_python的encode和decode误读总结
  7. Tomcat(Windows)
  8. php文件防删改,PHP实现增删改查以及防SQL注入
  9. linux防火墙服务关闭,Linux防火墙(firewall)的开启与关闭
  10. 蚂蚁集团前三季度营收1181.91亿元 支付宝月活用户7.31亿
  11. 生成图片_GitHub Star 3.2K Java 图片缩略图生成库
  12. 【脑筋急转弯】—— 谁是诚实人?
  13. 网络安装ubuntu操作系统
  14. CentOS 7 安装中文环境
  15. RocketMQ(六)多Master多Slave模式-异步复制集群搭建
  16. unity android gyro,Unity - 陀螺仪 - 仅绕一轴旋转
  17. BlueKing3-作业平台
  18. AW笔记本升级SSD,外接双屏中的一些注意事项
  19. 如何设置excel中一部分表格显示但是不打印?
  20. 认认真真做事,踏踏实实做人

热门文章

  1. C# 发邮件 服务器响应为: 5.7.0 Must issue a STARTTLS command first
  2. java 整数 字节数组_将整数转换为字节数组(Java)
  3. eui自带字体是什么_阿里巴巴居然出品了两款字体,免费可商用,网友:太良心了...
  4. java简单课程设计_!高分跪求帮忙写一个简单小程序的JAVA课程设计报告(内详!!)...
  5. linux连接wifi账户密码忘了怎么办,路由器账户密码忘记了怎么办_无线路由器密码忘记了怎么找回-系统城...
  6. gui窗口遮挡算法_软件更新丨AWTK 1.2 发布,国产开源 GUI 引擎
  7. android handler,Android中Handler原理
  8. ios设置中性黑体_ios 解决自定义字体无法显示问题
  9. 【机器学习算法】XGBoost
  10. 为了OFFER,花了几个小时,刷下Leetcode链表算法题