Springboot项目开启Tomcat的AccessLog,并打印指定的Header内容

Springboot项目开启Tomcat的AccessLog。设置AccessLog样式,并打印指定的Header内容

SpringBoot项目开启Tomcat的AccessLog

server.tomcat.basedir=my-tomcat
server.tomcat.accesslog.enabled=true

指定打印Header

server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)  %{xxx}i

%{xxx}i 就是打印指定Header的写法,其中xxx 就是header的name

SpringBoot配置文件参考示例

server.tomcat.accesslog.buffered=true # 缓冲输出,使其只定期刷新。
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # 要放在日志文件名中的日期格式。rotate为false的时候,这个也就不生效了。
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request.
server.tomcat.accesslog.rotate=true # Enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.

常用的样式参数

  • %a - Remote IP address,远程ip地址,注意不一定是原始ip地址,中间可能经过nginx等的转发
  • %A - Local IP address,本地ip
  • %b - Bytes sent, excluding HTTP headers, or ‘-’ if no bytes were sent
  • %B - Bytes sent, excluding HTTP headers
  • %h - Remote host name (or IP address if enableLookups for the connector is false),远程主机名称(如果resolveHosts为false则展示IP)
  • %H - Request protocol,请求协议
  • %l - Remote logical username from identd (always returns ‘-’)
  • %m - Request method,请求方法(GET,POST)
  • %p - Local port,接受请求的本地端口
  • %q - Query string (prepended with a ‘?’ if it exists, otherwise an empty string
  • %r - First line of the request,HTTP请求的第一行(包括请求方法,请求的URI)
  • %s - HTTP status code of the response,HTTP的响应代码,如:200,404
  • %S - User session ID
  • %t - Date and time, in Common Log Format format,日期和时间,Common Log 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),当前请求的线程名,可以和打印的log对比查找问题
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/u013732378/article/details/100151205

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值