Skip to content

Commit

Permalink
merge: 로그백 xml 구성
Browse files Browse the repository at this point in the history
Feature/#287 스프링 로그 모니터링 구성
  • Loading branch information
hong-sile authored Aug 17, 2023
2 parents a086606 + 56e73c6 commit 56b7a5a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
@RestControllerAdvice
public class GlobalControllerAdvice {

@ExceptionHandler(BaseException.class)
Expand All @@ -23,7 +23,8 @@ public ResponseEntity<ExceptionResponse> handleException(final BaseException e)
final BaseExceptionType type = e.exceptionType();

if (type.httpStatus().is5xxServerError()) {
log.error("[ERROR] MESSAGE : {}, 로그 캡처와 함께 서버 개발자에게 연락주세요 : ", type.errorMessage(), e);
log.error("[ERROR] MESSAGE : {}, 로그 캡처와 함께 서버 개발자에게 연락주세요 : ", type.errorMessage(),
e);
return new ResponseEntity<>(ExceptionResponse.from(e), HttpStatus.INTERNAL_SERVER_ERROR);
}

Expand Down Expand Up @@ -52,7 +53,7 @@ public ResponseEntity<ExceptionResponse> handleHttpMessageNotReadableException(
@ExceptionHandler(MissingServletRequestParameterException.class)
public ResponseEntity<ExceptionResponse> handleMissingServletRequestParameterException(
final MissingServletRequestParameterException e) {
final String message = "요청 파라미터가 올바르지 않습니다..";
final String message = "요청 파라미터가 올바르지 않습니다.";
log.warn("[WARN] MESSAGE: " + message);
return new ResponseEntity<>(new ExceptionResponse(message), HttpStatus.BAD_REQUEST);
}
Expand Down
78 changes: 78 additions & 0 deletions backend/emm-sale/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATTERN"
value="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n"/>
<!-- Appenders -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}
</pattern>
</encoder>
</appender>

<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/info.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_PATTERN}
</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>

<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/warn.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_PATTERN}
</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/warn.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>

<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/error.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${LOG_PATTERN}
</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>

<!-- Loggers -->
<logger name="com.emmsale" level="warn">
<appender-ref ref="WARN_FILE"/>
<appender-ref ref="ERROR_FILE"/>
</logger>

<!-- Root Logger -->
<root level="info">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="INFO_FILE"/>
</root>
</configuration>

0 comments on commit 56b7a5a

Please sign in to comment.