[feature] add loki handler.

This commit is contained in:
dalbodeule
2025-07-16 13:01:39 +09:00
parent 66df771cb7
commit e21641da7b
4 changed files with 15 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ repositories {
dependencies {
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
implementation("ch.qos.logback:logback-classic:1.5.13")
implementation("com.github.loki4j:loki-logback-appender:2.0.0")
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

View File

@@ -204,6 +204,7 @@ class UserHandler(
val logger: Logger,
private var user: User,
var streamStartTime: LocalDateTime?,
val chatLogger: Logger = LoggerFactory.getLogger("${channel.channelName}-chat"),
) {
lateinit var client: ChzzkClient
lateinit var chatChannelId: String
@@ -370,6 +371,7 @@ class UserHandler(
GlobalScope.launch {
delay(100L)
client.sendChatToLoggedInChannel(msg.limitUtf8Length(100))
chatLogger.info("[SEND]${channel.channelName}: ${msg.limitUtf8Length(100)}{${msg.length} / 100}")
}
}
}

View File

@@ -31,6 +31,7 @@ class MessageHandler(
private val channel = handler.channel
private val logger = handler.logger
private val chatLogger = handler.chatLogger
private val listener = handler.listener
private val dispatcher: CoroutinesEventBus by inject(CoroutinesEventBus::class.java)
@@ -372,7 +373,7 @@ class MessageHandler(
internal fun handle(msg: SessionChatMessage, user: User) {
if(msg.senderChannelId == ChzzkHandler.botUid) return
chatLogger.info("[RECV]${channel.channelName}: ${msg.content}{${msg.content.length} / 100}")
val commandKey = msg.content.split(' ')[0]
commands[commandKey.lowercase()]?.let { it(msg, user) }
}

View File

@@ -10,6 +10,13 @@
</encoder>
</appender>
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<labels>
app = chibot-chzzk-bot
host = ${LOKI_ENDPOINT:http://localhost:3100/loki/api/v1/push}
</labels>
</appender>
<!-- HikariCP 로그 레벨 설정 -->
<logger name="com.zaxxer.hikari" level="INFO" />
<logger name="o.m.jdbc.client.impl.StandardClient" level="INFO" />
@@ -31,5 +38,8 @@
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
<root level="INFO">
<appender-ref ref="LOKI" />
</root>
</configuration>