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

Logback 구성 및 환경별 설정 #235

Merged
merged 13 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 17 additions & 0 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">

<timestamp key="DATE_FORMAT"
datePattern="yyyy-MM-dd"/>

<!-- Local 개발환경 로그 설정 -->
<springProfile name="default">
<include resource="logger/logback-spring-local.xml"/>
</springProfile>

<!-- Development 환경 로그 설정 -->
<springProfile name="dev">
<include resource="logger/logback-spring-dev.xml"/>
</springProfile>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>

<included>
<appender name="console-appender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[%highlight(%level)][%d{MM-dd HH:mm:ss}][%magenta(%8X{correlationId})][%highlight(%replace(%logger{20}){'\\w\\.', ''})] %msg %n</pattern>
</layout>
</appender>
</included>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>

<included>
<appender name="parameter-appender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern> ⚡️ %replace(%msg){' \\[(\\d*)\\] as \\[\\w*\\] - ', '$1 - '} %n</pattern>
</layout>
</appender>
</included>
25 changes: 25 additions & 0 deletions backend/src/main/resources/logger/file/error-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<included>
<appender name="error-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOG_FILE_PATH}/${DATE_FORMAT}/error/error.log</file>

<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<encoder>
<pattern>[%boldRed(%level)][%d{MM-dd HH:mm:ss}][%magenta(%8X{correlationId})][%boldRed(%replace(%logger{20}){'\\w\\.', ''}:%line)] %msg %n</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_PATH}/${DATE_FORMAT}/error/error%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>180</maxHistory>
</rollingPolicy>

</appender>
</included>
25 changes: 25 additions & 0 deletions backend/src/main/resources/logger/file/info-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<included>
<appender name="info-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOG_FILE_PATH}/${DATE_FORMAT}/info/info.log</file>

<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<encoder>
<pattern>[%cyan(%level)][%d{MM-dd HH:mm:ss}][%magenta(%8X{correlationId})][%blue(%replace(%logger{20}){'\\w\\.', ''})] %msg %n</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_PATH}/${DATE_FORMAT}/info/info%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>180</maxHistory>
</rollingPolicy>

</appender>
</included>
25 changes: 25 additions & 0 deletions backend/src/main/resources/logger/file/warn-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<included>
<appender name="warn-appender" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOG_FILE_PATH}/${DATE_FORMAT}/warn/warn.log</file>

<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<encoder>
<pattern>[%red(%level)][%d{MM-dd HH:mm:ss}][%magenta(%8X{correlationId})][%red(%replace(%logger{20}){'\\w\\.', ''}:%line)] %msg %n</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE_PATH}/${DATE_FORMAT}/warn/warn%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>180</maxHistory>
</rollingPolicy>

</appender>
</included>
16 changes: 16 additions & 0 deletions backend/src/main/resources/logger/logback-spring-dev.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
<include resource="logger/file/info-appender.xml"/>
<include resource="logger/file/warn-appender.xml"/>
<include resource="logger/file/error-appender.xml"/>

<property name="LOG_FILE_PATH"
value="./logs/dev"/>

<root level="INFO">
<appender-ref ref="info-appender"/>
<appender-ref ref="warn-appender"/>
<appender-ref ref="error-appender"/>
</root>

</configuration>
23 changes: 23 additions & 0 deletions backend/src/main/resources/logger/logback-spring-local.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds">
<include resource="logger/console/console-appender.xml"/>
<include resource="logger/console/parameter-appender.xml"/>

<logger name="org.springframework.boot" level="INFO">
<appender-ref ref="console-appender"/>
</logger>

<logger name="codezap" level="TRACE">
<appender-ref ref="console-appender"/>
</logger>

<logger name="org.hibernate.orm.jdbc.bind" level="TRACE">
<appender-ref ref="parameter-appender"/>
</logger>

<!-- 전체 로그 확인이 필요한 경우 활성화 시킬 것 -->
<!-- <logger name="root" level="TRACE">-->
<!-- <appender-ref ref="console-appender"/>-->
<!-- </logger>-->

</configuration>