Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
logs/

### STS ###
.apt_generated
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,18 @@ services:
- SPRING_PROFILES_ACTIVE=prod
- SPRING_DATA_REDIS_HOST=redis
- SPRING_DATA_REDIS_PORT=6379
volumes:
- ./logs:/var/log/spring
depends_on:
- redis

alloy:
image: grafana/alloy:latest
container_name: alloy
ports:
- "12345:12345"
volumes:
- ./logs:/var/log/spring
- ./docs/config.alloy:/etc/alloy/config.alloy:ro
environment:
- ALLOY_ENV=production
13 changes: 13 additions & 0 deletions docker-compose.stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ services:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=stage
volumes:
- ./logs:/var/log/spring
depends_on:
- redis
network_mode: host

alloy:
image: grafana/alloy:latest
container_name: alloy
ports:
- "12345:12345"
volumes:
- ./logs:/var/log/spring
- ./docs/config.alloy:/etc/alloy/config.alloy:ro
environment:
- ALLOY_ENV=stage
37 changes: 37 additions & 0 deletions docs/config.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
livedebugging {
enabled = true
}

logging {
level = "info"
format = "logfmt"
}

local.file_match "spring_logs" {
path_targets = [{ __path__ = "/var/log/spring/*.log" }] // 서비스 로그 파일 경로
}

loki.source.file "spring_source" {
targets = local.file_match.spring_logs.targets // 위에서 정의한 로그 파일 경로 사용
forward_to = [loki.process.spring_labels.receiver] // 읽은 로그를 처리 단계로 전달
}

loki.process "spring_labels" {
forward_to = [loki.write.grafana_loki.receiver] // 처리된 로그를 Loki로 전송

stage.static_labels {
values = {
service = "backend",
env = sys.env("ALLOY_ENV"),
}
}
}

loki.write "grafana_loki" {
endpoint {
url = "http://monitor.solid-connection.com:3100/loki/api/v1/push"
tenant_id = "fake" // Loki 테넌트 ID (싱글 테넌시이기에 fake로 설정)
batch_wait = "1s" // 로그 배치 전송 대기 시간
batch_size = "1MB" // 로그 배치 크기
}
}
35 changes: 35 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>

<springProperty scope="context" name="activeProfile" source="spring.profiles.active"/>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/spring/solid-connection-server.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 매일 로그를 롤링 -->
<fileNamePattern>/var/log/spring/solid-connection-server.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory> <!-- 최근 30일 로그 보관 -->
</rollingPolicy>

<encoder>
<!-- Loki에서 읽기 좋은 logfmt 형식 (간단한 key=value 스타일) -->
<pattern>timestamp=%d{yyyy-MM-dd'T'HH:mm:ss.SSS} level=%-5level thread=%thread logger=%logger{36}
message=%msg%n
</pattern>
</encoder>
</appender>

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

<springProfile name="prod,stage">
<root level="INFO">
<appender-ref ref="FILE"/>
</root>
</springProfile>
</configuration>
Loading