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

Feature: 로그 설정(#83) #84

Merged
merged 2 commits into from
Dec 3, 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
8 changes: 2 additions & 6 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ out/
!**/src/main/**/out/
!**/src/test/**/out/

application*
backend/src/main/resources/application.yml
!backend/src/main/resources/logback-spring.xml
### NetBeans ###
/nbproject/private/
/nbbuild/
/nbbuild
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### log ###
log/*
src/main/resources/application.yml
7 changes: 7 additions & 0 deletions backend/src/main/resources/logback/console-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<included>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
</included>
18 changes: 18 additions & 0 deletions backend/src/main/resources/logback/file-error-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<included>
<appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>build/libs/aimo-backend-prod-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
</included>
13 changes: 13 additions & 0 deletions backend/src/main/resources/logback/file-info-appender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<included>
<appender name="FILE-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>build/libs/aimo-backend-dev-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
</appender>
</included>
64 changes: 64 additions & 0 deletions backend/src/main/resources/logback/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="60 seconds">
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>

<!--CONSOLE에 찍히는 로그와 FILE에 찍히는 로그 다르게(색상 유무)-->
<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %clr(%5level) %cyan(%logger) - %msg%n"/>
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %5level %logger - %msg%n"/>


<!--프로필별로 로그 설정-->
<!--local: 콘솔에 출력-->
<springProfile name="local">

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

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</root>

<logger level="INFO" name="aimo.backend"/>

<logger level="DEBUG" name="org.hibernate.SQL">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</logger>

<logger level="TRACE" name="org.hibernate.type.descriptor.sql.BasicBinder">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</logger>
</springProfile>

<!--dev:콘솔, 파일 둘다 출력-->
<springProfile name="dev">

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

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</root>

<logger level="INFO" name="aimo.backend"/>

<logger level="DEBUG" name="org.hibernate.SQL">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</logger>

<logger level="TRACE" name="org.hibernate.type.descriptor.sql.BasicBinder">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE-INFO"/>
</logger>
</springProfile>

</configuration>




Loading