Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,41 @@
<version>1.9.4</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>2.0.7</version>
</dependency>
<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

</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.3.11</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.11</version>
</dependency>

<!-- mongodb -->
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.springframework" level="INFO"/>
<logger name="springfox.documentation" level="ERROR"/>

</configuration>
18 changes: 18 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,25 @@
classpath*:common/*.xml
</param-value>
</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

<init-param>
<param-name>excludes</param-name>
<param-value>swagger-ui.html</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>TeeFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<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으로 로깅을 하지 않도록 함.

</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
Expand Down
29 changes: 29 additions & 0 deletions tomcat/conf/logback-access.xml
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로 처리가 가능함 ㅠ..

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<configuration>
<property name="LOG_PATH_NAME" value="${user.home}/http-access.log"/>
<property name="HTTP_PATTERN" value="%n-------- INFO --------%n- time: %t{yyyy-MM-dd HH:mm:ss}%n- summary: %a\t%r\t%s%n%n-------- HTTP REQUEST --------%n%header{Referer}\t%header{User-Agent}\t%D\t%I%n%fullRequest%n-------- HTTP RESPONSE --------%n%fullResponse%n--------%n"/>


<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH_NAME}/access.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH_NAME}/access.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${HTTP_PATTERN}</pattern>
</encoder>
</appender>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${HTTP_PATTERN}</pattern>
</encoder>
</appender>

<logger name="org.springframework" level="ERROR"/>
<logger name="springfox.documentation" level="ERROR"/>
<logger name="springfox.documentation.schema.property.bean.BeanModelProperty" level="INFO"/>

<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
</configuration>