-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #630 from tukcomCD2024/feat/layer_loggin-B-#629
feat : AOP를 이용한 log trace
- Loading branch information
Showing
4 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
backend/core/src/main/java/site/timecapsulearchive/core/global/log/LoggingComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Submodule config
updated
from 1ee7ab to 9340cf