Skip to content

Commit

Permalink
Merge pull request #630 from tukcomCD2024/feat/layer_loggin-B-#629
Browse files Browse the repository at this point in the history
feat : AOP를 이용한 log trace
  • Loading branch information
seokho-1116 authored Aug 11, 2024
2 parents 43b2f85 + 356a74e commit 58073e7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.locationtech.jts.geom.Point;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.timecapsulearchive.core.domain.capsule.data.dto.CapsuleBasicInfoDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package site.timecapsulearchive.core.global.log;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class LoggingComponent {

@Before("execution(* site.timecapsulearchive..*(..)) "
+ "&& !within(site.timecapsulearchive.core.infra..config..*)"
+ "&& !within(site.timecapsulearchive.core.domain..api..*)"
+ "&& !within(site.timecapsulearchive.core.global..*)"
+ "|| within(site.timecapsulearchive.core.global.api..*)"
+ "|| within(site.timecapsulearchive.core.global.geography..*)")
public void doTraceBefore(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();

log.info("[before] {} args={}", joinPoint.getSignature(), args);
}

@After("execution(* site.timecapsulearchive..*(..)) "
+ "&& !within(site.timecapsulearchive.core.infra..config..*)"
+ "&& !within(site.timecapsulearchive.core.domain..api..*)"
+ "&& !within(site.timecapsulearchive.core.global..*)"
+ "|| within(site.timecapsulearchive.core.global.api..*)"
+ "|| within(site.timecapsulearchive.core.global.geography..*)")
public void doTraceAfter(JoinPoint joinPoint) {
log.info("[after] {}", joinPoint.getSignature());
}
}
71 changes: 46 additions & 25 deletions backend/core/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://10.0.0.8:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>app=${name},host=${HOSTNAME},level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>
{
"level":"%level",
"class":"%logger{36}",
"thread":"%thread",
"message": "%message",
"requestId": "%X{X-Request-ID}"
}
</pattern>
</message>
</format>
</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{36} - %msg%n
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - [trace] %msg%n
</Pattern>
</layout>
</appender>
<appender name="INFO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/info.log</file>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{35} - %msg%n
</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>./logs/info.%d{yyyy-MM-dd}.%i.log.gz
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>180</maxHistory>
</rollingPolicy>
</appender>
<root level="INFO">

<springProfile name="prod">
<logger name="org.hibernate" level="error" additivity="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="LOKI"/>
</logger>

<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="LOKI"/>
</root>
</springProfile>

<springProfile name="local | dev | test | container">
<logger name="org.hibernate" level="error" additivity="false">
<appender-ref ref="INFO_LOG"/>
<appender-ref ref="STDOUT"/>
</logger>
<appender-ref ref="INFO_LOG"/>
</root>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</springProfile>
</configuration>
2 changes: 1 addition & 1 deletion backend/notification/src/main/resources/config

0 comments on commit 58073e7

Please sign in to comment.