반응형
Access 로그는 Tomcat에 HTTP 클라이언트의 접속하는 정보를 기록하는 로그파일이다. 주로 Apache나 NginX와 같은 Web Server에서 클라이언트 접속기록으로 중요한 파일이지만, Tomcat 역시 Web Server 기능으로 브라우저에서 HTTP Connector로 직접 접속할 수 있으므로 Access 로그 기능을 지원하고 있다. 참고로 AJP 커넥터를 통해 접속하면 Access 로그에 기록하지 않는다.
Access 로그 설정
server.xml 파일의 <Host> 섹션에 아래 예시와 같이 설정할 수 있다
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/logs/accesslog" prefix="localhost_access" suffix=".log" pattern="common" /> |
주요 속성은 다음과 같다.
- checkExists - 파일 존재 여부 체크
- buffered - access 로그 출력 시에 버퍼링 여부. 기본값은 true이고, false로 설정하면, 접근 시에 바로 로그 출력됨
- directory - access 로그 생성할 디렉터리
- prefix, suffix - access 로그 파일명
- pattern - 로그 포맷, "common"은 표준 포맷이고, "combined"는 확장 포맷
파일 rotate 관련해서 속성은 아래와 같다.
- maxDays - 보관일 수, 기본값은 -1이므로 삭제하지 않음인데, 30으로 설정하면 30일만 access 로그 파일 보관
- rotatable - access 로그 파일을 rotate 할 것인지 여부. 기본값은 true이고, false로 설정하면 rotate 하지 않음
- fileDateFormat - 기본값은 .yyyy-MM-dd 이므로 매일 rotate됨. 시간별로 rotate하고 싶으면, .yyyy-MM-dd.HH라고 설정하면 됨
pattern 에서 주로 사용하는 포맷은 아래의 2가지 포맷이다. 각 항목에 대해서는 아래 설명되어 있다. 이는 Web Server도 유사하다.
- common - %h %l %u %t "%r" %s %b
- combined - %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"
주요 필드에 대한 설명은 아래와 같다:
- %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)
'WAS > Tomcat' 카테고리의 다른 글
[정보] Tomcat Manager 관리자 패스워드 암호화 (0) | 2019.10.07 |
---|---|
[정보] Tomcat Manager 설정 (0) | 2019.10.01 |
[정보] Tomcat Native(APR) Connector 이해 (0) | 2019.10.01 |
[Tips] 특정 IP에서 WebApp에 대한 접근 차단 (0) | 2018.05.12 |
[Tips] Tomcat 버전 확인 (0) | 2018.02.22 |