Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] refactor: Logback에서 슬랙으로 알람을 보내는 기능을 제거하고, ErrorLoggerConfig를 삭제한다. (#875) #878

Merged
merged 3 commits into from
Apr 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.event.Level;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
Expand All @@ -31,14 +30,12 @@ public class LogRequestBodyAspect {

private final Map<Level, BiConsumer<String, String>> loggerMap = new EnumMap<>(Level.class);
private final ObjectMapper objectMapper;
private final Logger errorLogger;

public LogRequestBodyAspect(ObjectMapper objectMapper, Logger errorLogger) {
public LogRequestBodyAspect(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
this.errorLogger = errorLogger;
loggerMap.put(Level.INFO, this.errorLogger::info);
loggerMap.put(Level.WARN, this.errorLogger::warn);
loggerMap.put(Level.ERROR, this.errorLogger::error);
loggerMap.put(Level.INFO, log::info);
loggerMap.put(Level.WARN, log::warn);
loggerMap.put(Level.ERROR, log::error);
}

@Around("@annotation(LogRequestBody)")
Expand All @@ -49,7 +46,7 @@ public Object handleAll(ProceedingJoinPoint pjp) throws Throwable {
Level level = annotation.level();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

if (attributes == null || !errorLogger.isEnabledForLevel(level)) {
if (attributes == null || !log.isEnabledForLevel(level)) {
return pjp.proceed();
}
HttpServletRequest request = attributes.getRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
Expand All @@ -31,6 +32,7 @@
@RequiredArgsConstructor
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

private static final Logger log = LoggerFactory.getLogger("ErrorLogger");
private static final String LOG_FORMAT_INFO = "\n[🔵INFO] - ({} {})\n(id: {}, role: {})\n{}\n {}: {}";
private static final String LOG_FORMAT_WARN = "\n[🟠WARN] - ({} {})\n(id: {}, role: {})";
private static final String LOG_FORMAT_ERROR = "\n[🔴ERROR] - ({} {})\n(id: {}, role: {})";
Expand Down Expand Up @@ -60,7 +62,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
*/

private final AuthenticateContext authenticateContext;
private final Logger errorLogger;

@ExceptionHandler(InvalidMediaTypeException.class)
public ResponseEntity<ErrorResponse> handle(InvalidMediaTypeException e) {
Expand Down Expand Up @@ -133,23 +134,17 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
}

private void logInfo(FestaGoException e, HttpServletRequest request) {
if (errorLogger.isInfoEnabled()) {
errorLogger.info(LOG_FORMAT_INFO, request.getMethod(), request.getRequestURI(), authenticateContext.getId(),
authenticateContext.getRole(), e.getErrorCode(), e.getClass().getName(), e.getMessage());
}
log.info(LOG_FORMAT_INFO, request.getMethod(), request.getRequestURI(), authenticateContext.getId(),
authenticateContext.getRole(), e.getErrorCode(), e.getClass().getName(), e.getMessage());
}

private void logWarn(FestaGoException e, HttpServletRequest request) {
if (errorLogger.isWarnEnabled()) {
errorLogger.warn(LOG_FORMAT_WARN, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
log.warn(LOG_FORMAT_WARN, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}

private void logError(Exception e, HttpServletRequest request) {
if (errorLogger.isErrorEnabled()) {
errorLogger.error(LOG_FORMAT_ERROR, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
log.error(LOG_FORMAT_ERROR, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
}
15 changes: 0 additions & 15 deletions backend/src/main/java/com/festago/config/ErrorLoggerConfig.java

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/main/resources/config
8 changes: 0 additions & 8 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@
<include resource="logs/error/file-info-appender.xml"/>
<include resource="logs/error/file-warn-appender.xml"/>
<include resource="logs/error/file-error-appender.xml"/>
<include resource="logs/slack/slack-error-appender.xml"/>

<logger additivity="false" level="INFO" name="ErrorLogger">
<appender-ref ref="ERROR_ERROR"/>
<appender-ref ref="ERROR_WARN"/>
<appender-ref ref="ERROR_INFO"/>
<appender-ref ref="ASYNC_SLACK_ERROR"/>
</logger>

<root level="INFO">
<appender-ref ref="FILE-INFO"/>
<appender-ref ref="FILE-WARN"/>
<appender-ref ref="FILE-ERROR"/>
<appender-ref ref="ASYNC_SLACK_ERROR"/>
</root>
</springProfile>

Expand All @@ -44,22 +41,17 @@
<include resource="logs/error/file-info-appender.xml"/>
<include resource="logs/error/file-warn-appender.xml"/>
<include resource="logs/error/file-error-appender.xml"/>
<include resource="logs/slack/slack-error-appender.xml"/>
<include resource="logs/slack/slack-warn-appender.xml"/>

<logger additivity="false" level="INFO" name="ErrorLogger">
<appender-ref ref="ERROR_ERROR"/>
<appender-ref ref="ERROR_WARN"/>
<appender-ref ref="ERROR_INFO"/>
<appender-ref ref="ASYNC_SLACK_ERROR"/>
<appender-ref ref="ASYNC_SLACK_WARN"/>
</logger>

<root level="INFO">
<appender-ref ref="FILE-INFO"/>
<appender-ref ref="FILE-WARN"/>
<appender-ref ref="FILE-ERROR"/>
<appender-ref ref="ASYNC_SLACK_ERROR"/>
</root>
</springProfile>

Expand Down
20 changes: 0 additions & 20 deletions backend/src/main/resources/logs/slack/slack-error-appender.xml

This file was deleted.

20 changes: 0 additions & 20 deletions backend/src/main/resources/logs/slack/slack-warn-appender.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.festago.support;

import com.festago.common.aop.ValidPageableAspect;
import com.festago.config.ErrorLoggerConfig;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -12,8 +11,7 @@

@EnableAspectJAutoProxy
@WebMvcTest
@Import({TestAuthConfig.class, ErrorLoggerConfig.class, MockAllServiceBeanFactoryPostProcessor.class,
ValidPageableAspect.class})
@Import({TestAuthConfig.class, MockAllServiceBeanFactoryPostProcessor.class, ValidPageableAspect.class})
@Retention(RetentionPolicy.RUNTIME)
@TestExecutionListeners(value = {MockAuthTestExecutionListener.class,
ResetMockTestExecutionListener.class}, mergeMode = MergeMode.MERGE_WITH_DEFAULTS)
Expand Down
Loading