1. 程式人生 > 其它 >SpringBoot專案 配置tomcat access_log日誌

SpringBoot專案 配置tomcat access_log日誌

在配置檔案application.yml裡面來配置tomcat accesslog日誌:

server:
  port: 80
  tomcat:
    accesslog:
      enabled: true
      directory: D:\Documents\D_程式碼相關\J_java\sprintboot_study
      prefix: tomcat_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

日誌記錄格式(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)