Skip to content

Conversation

@Invidam
Copy link
Contributor

@Invidam Invidam commented Mar 5, 2024

▶ Request

Content

#348

as-is

  • 로깅 부재

to-be

  • 로깅 추가하기 위한 코드 추가

예시 모습

######## INFO ########
- time: 2024-03-05 17:44:58
- summary: 0:0:0:0:0:0:0:1	GET / HTTP/1.1	200

######## HTTP REQUEST ########
-	Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36	19	http-nio-8080-exec-5
GET / HTTP/1.1
host: localhost:8080
connection: keep-alive
sec-ch-ua: "Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
sec-fetch-site: none
sec-fetch-mode: navigate
sec-fetch-user: ?1
sec-fetch-dest: document
accept-encoding: gzip, deflate, br, zstd
accept-language: en,ko;q=0.9,en-US;q=0.8
cookie: JSESSIONID=7329FC27D8213FE914A761AEE5A3F201


######## HTTP RESPONSE ########
HTTP/1.1 200 OK
Access-Control-Allow-Methods: POST, GET, DELETE, PUT
Set-Cookie: JSESSIONID=32CD8A5293A7FDA52BC3808AA5A67C71; Path=/; HttpOnly
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: X-Requested-With, Origin, Content-Type, Accept, Authorization



<html>
<head>
    <title>Title</title>
</head>
<body>
Spring Project
</body>
</html>


--------

🧪 Test

  • 로컬에서 동작여부 테스트 (추후 dev에서도 해봐야 함)

논의사항

전제

dev 환경의 톰캣 환경설정 (tomcat/conf)를 수정해주어야 함.

  • server.xml 일부
  • logback-access.xml 추가
  • logback-access jar 추가

방법1

수동으로 추가해준 후 해당 내용을 문서화 (기존 방식)

방법2

자동으로 추가되도록 스크립트를 작성

  • 문제점
    • 톰캣 버전, 톰캣 위치 등을 숨겨줘야 하는 번거로움
    • 부트로 이관시 효용 감소
  • 장점
    • 알아야 하는 내용 감소
    • 자동화 가능

하고싶은 방법

방법1로 진행하고 싶다.
왜냐하면 (1) 빠르게 적용해야하고 (2) 부트로 이관하는 전까지만 문서로 관리하는 건 어렵지 않을 것 같다.

참고

@Invidam Invidam self-assigned this Mar 5, 2024
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.3.11</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java버전별 logback 버전: https://logback.qos.ch/news.html

</context-param>
<filter>
<filter-name>TeeFilter</filter-name>
<filter-class>ch.qos.logback.access.servlet.TeeFilter</filter-class>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeeFilter 라는 Spring Filter (라이브러리에서 구현됨)에서 HTTP들을 캡쳐함.

참고: https://logback.qos.ch/access.html#teeFilter

<filter-mapping>
<filter-name>TeeFilter</filter-name>
<url-pattern>/swagger-ui.html</url-pattern> <!-- Add the URL pattern you want to exclude -->
<dispatcher>REQUEST</dispatcher> <!-- Exclude only request type -->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swagger 문서를 응답해주는 경우 body(html)이 너무 길어져서, 해당 경우는 url pattern으로 로깅을 하지 않도록 함.

Copy link
Contributor Author

@Invidam Invidam Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullRequest가 HTTP 요청 메시지를 로깅하는 레이아웃인데, (참고: https://logback.qos.ch/manual/layouts.html#fullRequest)

Spring3 에서는 이를 인식하지 못해서(PARSER_ERROR 발생) 톰캣의 conf에 해당 파일을 추가해주어야 함.
부트에서는 내장 톰캣이라 스프링 코드 or xml로 처리가 가능함 ㅠ..

Copy link
Member

@Choi-JJunho Choi-JJunho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인~ 이제 로깅이 점더 꼼곰해지겠네

@Invidam Invidam merged commit 14afd57 into develop Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants