티스토리 뷰

반응형

이전의 완전 초기 스타트업에서 Node.js/Express를 사용할 때, pm2를 통해 서버 관리를 한적이 있었다. pm2를 키면 access log를 바로 찍어줘서 request의 어느 부분에서 어떻게 오류가 나고 있고, 났었는지 확인하기가 편했다.

 

 

Spring boot를 사용해 개발을 시작한 후, access log를 잊고 있다가 'application log 말고 access log는 어떻게 보지?' 라는 생각이 들자 찾아보게되었다.

 

 

Spring boot를 사용하면 내부에 embedded tomcat이 있기에 따로 WAS를 띄울 필요가 없다. 이 tomcat에 대한 설정을 application.properties 또는 application.yml을 통해 설정할 수 있으며, 이를 통해 access.log를 찍을 수 있다.

 

 

상세한 access.log 설정은 해당 위치에서의 server.tomcat 설정들을 참고하자.

Common Application Properties

  • 설정에 따른 기본 값들도 잘 명시되어있으니 확인해보자.

 

대략적으로 중요한 옵션은 다음과 같다.

server:
  tomcat:
    basedir: .                              # access log를 저장할 base directory 지정
    accesslog:
      enabled: true                         # access log 저장 여부 (default: false)
      directory: logs                       # access log를 저장할 상세 directory (base directory에 기반한) (default: logs)
      pattern: '%h %l %u %t "%r" %s %b %D'  # access log 출력 패턴
      prefix: access                        # access log 파일이름 prefix
      suffix: .log                          # access log 파일이름 suffix (확장자 포함)
      rotate: true                          # access log rotation 여부
      rename-on-rotate: true                # rotation 시, 새로운 이름 지정 여부 (rotate 될 때의 날짜명이 로그 파일이름에 찍힘)

 

Log pattern의 경우, 다음 규칙을 따른다.

%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)

%{xxx}i for incoming headers
%{xxx}o for outgoing response headers
%{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)
320x100
반응형
댓글
반응형
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함