Skip to content

Commit

Permalink
♻️ 스케줄러 서버로 검색 로그 전송 (#254) (#278)
Browse files Browse the repository at this point in the history
* ♻️ logback 파일 모듈별로 분리 및 소켓 방식으로 변경

* feat: change scheduler hostname (#277)

* ♻️ profile에 따라 socket appender host name 수정

* ♻️ batch server에서 로그 받도록 socket-server 설정

* 🐛 테스트 실패 수정

* ♻️ test용 배포 브랜치 제거

* ♻️ test용 코드 제거

* ♻️ submodule update

---------

Co-authored-by: Joohyun Ha <[email protected]>
  • Loading branch information
semi-cloud and mangchhe authored Dec 9, 2024
1 parent 0f44295 commit 4bd8625
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ahachul_secret
100 changes: 100 additions & 0 deletions application/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<configuration scan="true" scanPeriod="60 seconds">

<property resource="logback.properties"/>

<springProperty scope="context" name="LOG_LEVEL" source="logging.level.root"/>

<property name="LOG_PATH" value="${log.config.path}"/>
<property name="LOG_FILE_NAME" value="${log.config.filename}"/>
<property name="LOG_ARCHIVE_PATH" value="${log.config.archive.path}"/>

<property name="ERROR_LOG_PATH" value="${log.config.error.path}"/>
<property name="ERROR_LOG_FILE_NAME" value="${log.config.error.filename}"/>
<property name="ERROR_LOG_ARCHIVE_PATH" value="${log.config.error.archive.path}"/>

<property name="HASHTAG_LOG_PATH" value="${log.config.hashtag.path}"/>
<property name="HASHTAG_LOG_FILE_NAME" value="${log.config.hashtag.filename}"/>

<springProfile name="dev">
<property name="HASHTAG_LOG_HOST_NAME" value="${log.config.hashtag.hostname}"/>
</springProfile>

<springProfile name="local, test">
<property name="HASHTAG_LOG_HOST_NAME" value="${log.config.hashtag.hostname.local}"/>
</springProfile>

<property name="HASHTAG_LOG_PORT" value="${log.config.hashtag.port}"/>

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

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE_NAME}.log</file>

<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE_PATH}/${LOG_FILE_NAME}.%d{yyyy-MM-dd}_%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>

<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${ERROR_LOG_PATH}/${ERROR_LOG_FILE_NAME}.log</file>

<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${LOG_PATTERN}</pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${ERROR_LOG_ARCHIVE_PATH}/${ERROR_LOG_FILE_NAME}.%d{yyyy-MM-dd}_%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>60</maxHistory>
</rollingPolicy>

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

<appender name="HASHTAG_SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
<remoteHost>${HASHTAG_LOG_HOST_NAME}</remoteHost>
<port>${HASHTAG_LOG_PORT}</port>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${HASHTAG_LOG_PATTERN}</pattern>
</encoder>
</appender>

<appender name="HASHTAG_ASYNC_SOCKET" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>512</queueSize>
<discardingThreshold>0</discardingThreshold>
<neverBlock>true</neverBlock>
<appender-ref ref="HASHTAG_SOCKET"/>
</appender>

<root level="{LOG_LEVEL}">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ERROR_FILE"/>
</root>

<logger name="HASHTAG_LOGGER" LEVEL="INFO">
<appender-ref ref="HASHTAG_ASYNC_SOCKET"/>
</logger>

</configuration>
5 changes: 4 additions & 1 deletion core/src/main/resources/logback.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ log.config.error.path=./error_logs
log.config.error.filename=error_log
log.config.error.archive.path=./error_logs/archive

log.config.hashtag.path=./logs/archive/hashtag
log.config.hashtag.path=./scheduler/logs/archive/hashtag
log.config.hashtag.filename=hashtag_log
log.config.hashtag.hostname=internal.scheduler
log.config.hashtag.hostname.local=localhost
log.config.hashtag.port=5001
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package backend.team.ahachul_backend

import backend.team.ahachul_backend.common.properties.SocketServerProperties
import ch.qos.logback.classic.net.SimpleSocketServer
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication
import org.springframework.context.ApplicationContext

@SpringBootApplication
@EnableConfigurationProperties
class ScheduleModuleApplication

fun main(args: Array<String>) {
runApplication<ScheduleModuleApplication>(*args)
val context: ApplicationContext = runApplication<ScheduleModuleApplication>(*args)
val properties = context.getBean(SocketServerProperties::class.java)
SimpleSocketServer.main(arrayOf(properties.port, properties.configPath))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package backend.team.ahachul_backend.common.properties

import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration

@Configuration
@ConfigurationProperties(prefix = "socket-server")
data class SocketServerProperties(
var port: String = "",
var configPath: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>30</maxHistory>
</rollingPolicy>

</appender>

<root level="{LOG_LEVEL}">
Expand Down

0 comments on commit 4bd8625

Please sign in to comment.