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

feat: 로깅 처리 추가 #626

Merged
merged 3 commits into from
Oct 19, 2022
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 @@ -4,14 +4,12 @@
import com.pickpick.slackevent.application.SlackEventServiceFinder;
import com.pickpick.slackevent.ui.dto.ChallengeRequest;
import com.pickpick.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/event")
public class SlackEventController {
Expand All @@ -27,8 +25,6 @@ public SlackEventController(final SlackEventServiceFinder slackEventServiceFinde

@PostMapping
public ResponseEntity<String> save(@RequestBody final String requestBody) {
log.info("Slack Event: {}", requestBody);

ChallengeRequest challengeRequest = JsonUtils.convert(requestBody, ChallengeRequest.class);
if (isUrlVerificationRequest(challengeRequest)) {
return ResponseEntity.ok(challengeRequest.getChallenge());
Expand Down
39 changes: 39 additions & 0 deletions backend/src/main/java/com/pickpick/support/LoggingAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pickpick.support;

import java.util.stream.Collectors;
import java.util.stream.IntStream;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.CodeSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class LoggingAspect {

@Pointcut("execution(* com.pickpick.*.ui.*Controller.*(..))")
private void loggingTarget() {

}

@Before("loggingTarget()")
public void logRequest(final JoinPoint joinPoint) {
CodeSignature signature = (CodeSignature) joinPoint.getSignature();

log.info("[Request] Controller: {} / Method: {} / Arguments: {}",
joinPoint.getTarget().getClass().getSimpleName(),
signature.getName(),
toString(signature.getParameterNames(), joinPoint.getArgs())
);
}

private String toString(final String[] parameterNames, final Object[] args) {
return IntStream.range(0, parameterNames.length)
.mapToObj(i -> parameterNames[i] + "=" + args[i])
.collect(Collectors.joining(","));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<included>
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender">

<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<pattern>
%highlight([%-5level]) %d{yyyy-MM-dd HH:mm:ss} %cyan([%thread]) %magenta([%logger{0}:%line])-%message%n
</pattern>
</encoder>

</appender>

<appender name="ASYNC_CONSOLE_APPENDER" class="ch.qos.logback.classic.AsyncAppender">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<included>
<appender name="FILE_APPENDER_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<timestamp key="DATE_FORMAT"
datePattern="yyyy-MM-dd"/>

<file>${FILE_PATH}/${DATE_FORMAT}/info/info.log</file>
<appender name="FILE_APPENDER_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${user.home}/logs/${DATE_FORMAT}/info/info.log</file>

<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
Expand All @@ -10,11 +12,13 @@
</filter>

<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<pattern>
[%-5level] %d{yyyy-MM-dd HH:mm:ss} [%thread] [%logger{0}:%line] - %message %n
</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${FILE_PATH}/%d{yyyy-MM-dd}/info/info_%i.log</fileNamePattern>
<fileNamePattern>${user.home}/logs/%d{yyyy-MM-dd}/info/info_%i.log</fileNamePattern>
<maxFileSize>5MB</maxFileSize>
<maxHistory>2</maxHistory>
<totalSizeCap>30MB</totalSizeCap>
Expand Down
12 changes: 0 additions & 12 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
<timestamp key="DATE_FORMAT"
datePattern="yyyy-MM-dd"/>

<property name="CONSOLE_LOG_PATTERN"
value="%highlight([%-5level]) %d{yyyy-MM-dd HH:mm:ss} %cyan([%thread]) %magenta([%logger{0}:%line]) - %message %n"/>

<property name="FILE_LOG_PATTERN"
value="[%-5level] %d{yyyy-MM-dd HH:mm:ss} [%thread] [%logger{0}:%line] - %message %n"/>

<property name="FILE_PATH"
value="${user.home}/logs"/>

<include resource="appenders/async-console-appender.xml"/>
<include resource="appenders/async-file-appender-info.xml"/>

Expand Down