본문 바로가기
Spring

[SpringBoot] tomcat access log 출력

by jungmin.park 2024. 1. 9.

SpringBoot의 web module에 있는 내장 톰캣은 기본적으로 access log를 출력하지 않는다.

다양한 방법으로 access log 혹은 그와 유사한 로그를 남길 수 있지만 전통적인 설치형 tomcat에서 access log를 남기는 것과 동일한 log 출력 방법을 설정해본다.

 

application.yml 설정

server:
  tomcat:
    accesslog:
      enabled: true
      directory: logs
      suffix: .log
      prefix: access_log
      file-date-format: .yyyy-MM-dd
      pattern: %{yyyy-MM-dd HH:mm:ss}t %s %r %{User-Agent}i %{Referer}i %a %b %D
      max-days: 14
    basedir: .
  • accesslog.enabled: true # 로그를 사용한다고 지정
  • accesslog.directory : logs # springboot 가 실행되는 디렉토리를 기본 디렉토리로 설정
  • accesslog.file-data-format : ~ # access log 파일 데이터 포맷 형식
  • accesslog.pattern : log 패턴을 지정

일반적인 로그 포맷을 사용하고 싶으면 accesslog.pattern=common 으로 설정하면 된다.

로그 포맷을 확장하고 싶으면 해당 패턴을 사용해 로그 포맷을 커스터마이징 할 수 있다.

%h – 요청을 보낸 클라이언트 IP
%l – 사용자 식별 정보
%u – HTTP 인증에 의해 지정된 사용자 이름
%t – 요청 시간
%r – 사용자 요청 URL
%s – HTTP 응답 코드 
%b – 응답 사이즈

 

'Spring' 카테고리의 다른 글

[IntelliJ] java.lang.ClassNotFoundException이 발생한 경우  (0) 2024.03.27
동시성제어(1) - Redis  (0) 2023.12.12