SpringBoot项目 配置tomcat access_log 日志

在配置文件application.yml里面来配置tomcat accesslog日志

在application.yml中添加如下配置:
server:
  tomcat:
    accesslog:
      enabled: true       // 是否打印accesslog日志。为true时为打印(默认是false)
      buffered: false      // 用于确定是否将缓冲日志记录的标志。如果设置为false,则将在每个请求之后写入访问日志。默认值:true
      directory: /data0/www/logs/xxxx.xx.com    // 日志文件存放的路径
      prefix: access_log    // 日志名称前缀
      suffix: .log    // 日志名称后缀
      file-date-format: -yyyy-MM-dd   // 日志文件名中的日期格式。以天为单位
      pattern: '%{X-Real-IP}i - %{Host}i %t "%r" %{Content-Length}i %s %b %D "%{Referer}i" "%{User-Agent}i" %a "%I" "-"'   // 见下
      rotate: true    // 是否启用日志轮转。默认为true(这个参数决定是否需要切换切换日志文件,如果被设置为false,则日志文件不会切换,即所有文件打到同一个日志文件中,
                      // 并且file-date-format参数也会被忽略) 

日志记录格式(pattern),形式参照 :
nginx 日志 log_format:

log_format main '$http_x_real_ip - $http_host [$time_local] "$request" $request_length '
                             '$status $body_bytes_sent $request_time "$http_referer" '
                             '"$http_user_agent" $remote_addr "-" "-" ';

tomcat access log pattern:

pattern: '%{X-Real-IP}i - %{Host}i %t "%r" %{Content-Length}i'
              '%s %b %D "%{Referer}i"'
             '"%{User-Agent}i" %a "%I" "-"'

%{X-Real-IP}i: http X-Real_IP
%{Host}i: http Host
%t: Date and time, in Common Log Format
%r: First line of the request (method and request URI)
%{Content-Length}i: request length
%s: HTTP status code of the response
%b: Bytes sent, excluding HTTP headers, or ‘-’ if zero
%D: Time taken to process the request, in millis
%{Referer}i: http Referer
%{User-Agent}i: http User-Agent
%a: Remote IP address
%I: Current request thread name (can compare later with stacktraces)

参考官方文档:

https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve
http://xiaobaoqiu.github.io/blog/2014/12/30/tomcat-access-logpei-zhi/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值