feat(loki): send logs to loki to centralize logs

This commit is contained in:
2025-11-13 18:24:13 +07:00
parent d59cd35476
commit 34b345c744
3 changed files with 23 additions and 0 deletions
+5
View File
@@ -17,6 +17,11 @@ JAVA_OPTS=-Xmx512m
# Logging configuration
LOG_LEVEL=INFO
LOKI_HOST=logs-prod-020.grafana.net
LOKI_PORT=443
LOKI_USERNAME=your_loki_username
LOKI_PASSWORD=your_loki_password
# App configuration
ENV=DEVELOPMENT
ADMIN_IDS=1000001999,1000002000,1000002001
+2
View File
@@ -24,6 +24,7 @@ configurations {
dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.36")
implementation("com.couchbase.client:java-client:3.7.6")
implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
implementation("com.google.code.gson:gson:2.11.0")
implementation("com.google.guava:guava:33.4.0-jre")
implementation("org.apache.commons:commons-math3:3.6.1")
@@ -32,6 +33,7 @@ dependencies {
implementation("org.telegram:telegrambots-client:8.0.0")
implementation("org.telegram:telegrambots-extensions:8.0.0")
implementation("org.telegram:telegrambots-longpolling:8.0.0")
implementation("pl.tkowalcz.tjahzi:log4j2-appender:0.9.32")
testAnnotationProcessor("org.projectlombok:lombok:1.18.36")
testImplementation(platform("org.junit:junit-bom:5.11.4"))
+16
View File
@@ -3,6 +3,8 @@
<Properties>
<Property name="CONSOLE_LOG_PATTERN">%d{HH:mm:ss.SSS} %5p --- [%t] %c : %m%n</Property>
<Property name="CONSOLE_LOG_CHARSET">UTF-8</Property>
<Property name="LOKI_LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %c : %m%n</Property>
<Property name="LOKI_LOG_CHARSET">UTF-8</Property>
</Properties>
<Appenders>
@@ -12,10 +14,24 @@
<ThresholdFilter level="TRACE"/>
</Filters>
</Console>
<Loki name="Loki">
<host>${env:LOKI_HOST}</host>
<port>${env:LOKI_PORT}</port>
<username>${env:LOKI_USERNAME}</username>
<password>${env:LOKI_PASSWORD}</password>
<PatternLayout pattern="${LOKI_LOG_PATTERN}" charset="${LOKI_LOG_CHARSET}"/>
<Label name="service_name" value="StoreScraperBot"/>
<Label name="environment" value="${env:ENV}"/>
</Loki>
</Appenders>
<Loggers>
<Root level="${env:LOG_LEVEL:-debug}">
<AppenderRef ref="ConsoleAppender"/>
<AppenderRef ref="Loki"/>
</Root>
</Loggers>
</Configuration>