Spring

[Springboot] Tomcat access log 설정

예은파파 2020. 11. 11. 22:45

 

# Spring boot의 embedded tomcat 사용 시  access log 설정 및 로그 Pattern 사용법

 

  • application.properties 설정
server.tomcat.accesslog.enabled = true
server.tomcat.accesslog.pattern = %{yyyy-MM-dd HH:mm:ss}t\t%s\t%r\t%{User-Agent}i\t%{Referer}i\t%a\t%b
server.tomcat.accesslog.directory = /log

- accesslog.directory 의 경우 로그가 쌓일 디렉토리 위치로 일반적으로는 /var/log/tomcat에 적재가 된다. 

  위의 예제는 /log 경로에 쌓이도록 설정 한 것이다.

 

  • accesslog에 적재되는 로그 Parrern Reference
    • %a - Remote IP address
    • %A - Local IP address
    • %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)
    • %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)

  • Header 또는 Cookie 등에서 특정 정보를 취할 때 사용하는 Pattern Reference
    • %{xxx}i Request Header 내의 정보
    • %{xxx}o Response Header 내의 정보
    • %{xxx}c 특정 Cookie 내용
    • %{xxx}r ServletRequest 의 특정 attribute
    • %{xxx}s HttpSession 의 특정 attribute
    • %{xxx}t DateFormat을 출력하기 위한 옵션
common - %h %l %u %t "%r" %s %b   
combined - %h %l %u %t "%r" %s %b **"%{Referer}i"** **"%{User-Agent}i"**

 

 

'Spring' 카테고리의 다른 글

[Spring] Build a Fat JAR With Maven  (0) 2020.10.29