From b41084695c7777eaede6a9e6161ce9b975c163e2 Mon Sep 17 00:00:00 2001 From: yuua Date: Tue, 26 Mar 2024 15:40:28 +0900 Subject: [PATCH] feat: configure logging by slf4j + log4j 2 --- .gitignore | 4 +-- .idea/kotlinc.xml | 2 +- build.gradle.kts | 30 +++++++++++++------ src/main/kotlin/com/jaoafa/vcspeaker/Main.kt | 6 +++- .../com/jaoafa/vcspeaker/tools/Emoji.kt | 7 +++-- src/main/resources/log4j2.xml | 21 +++++++++++++ 6 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/log4j2.xml diff --git a/.gitignore b/.gitignore index ed6adbf2..10946754 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,8 @@ build store/ -stores/ cache/ data/ +logs/ + config.yml -test.wav diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fdf8d994..ae3f30ae 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 15a252b1..e84bed2d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - kotlin("jvm") version "1.9.0" + kotlin("jvm") version "1.9.21" kotlin("plugin.serialization") version "1.8.0" application } @@ -20,26 +20,38 @@ dependencies { implementation(kotlin("reflect")) implementation("junit:junit:4.13.1") - implementation("ch.qos.logback:logback-classic:1.3.7") - implementation("com.github.aikaterna:lavaplayer-natives:original-SNAPSHOT") - implementation("com.github.ajalt.clikt:clikt:4.0.0") - implementation("com.kotlindiscord.kord.extensions:kord-extensions:1.6.0-SNAPSHOT") - implementation("com.uchuhimo:konf:1.1.2") - implementation("dev.arbjerg:lavaplayer:2.0.2") + // Logging + implementation("org.slf4j:slf4j-api:2.1.0-alpha1") + implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1") + implementation("org.apache.logging.log4j:log4j-core:2.23.1") + implementation("io.github.oshai:kotlin-logging-jvm:6.0.3") + + // Discord Related implementation("dev.kord:kord-core:unknown-d-field-fix-SNAPSHOT") implementation("dev.kord:kord-core-voice:0.13.1") implementation("dev.kord:kord-voice:0.13.1") + implementation("com.kotlindiscord.kord.extensions:kord-extensions:1.6.0-SNAPSHOT") + implementation("dev.arbjerg:lavaplayer:2.0.2") + implementation("com.github.aikaterna:lavaplayer-natives:original-SNAPSHOT") + + // Ktor implementation("io.ktor:ktor-client-cio-jvm:2.2.4") implementation("io.ktor:ktor-client-cio:2.2.4") implementation("io.ktor:ktor-client-content-negotiation:2.3.5") implementation("io.ktor:ktor-client-core:2.2.4") - implementation("io.sentry:sentry:6.30.0") - implementation("net.htmlparser.jericho:jericho-html:3.4") + + // Kotlinx implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") + + // Other Libraries + implementation("io.sentry:sentry:6.30.0") + implementation("net.htmlparser.jericho:jericho-html:3.4") implementation("org.reflections:reflections:0.10.2") implementation("com.google.cloud:google-cloud-vision:3.32.0") implementation("com.sksamuel.scrimage:scrimage-core:4.1.1") + implementation("com.github.ajalt.clikt:clikt:4.0.0") + implementation("com.uchuhimo:konf:1.1.2") } tasks.test { diff --git a/src/main/kotlin/com/jaoafa/vcspeaker/Main.kt b/src/main/kotlin/com/jaoafa/vcspeaker/Main.kt index 1602d6d3..dc65f6c4 100644 --- a/src/main/kotlin/com/jaoafa/vcspeaker/Main.kt +++ b/src/main/kotlin/com/jaoafa/vcspeaker/Main.kt @@ -16,6 +16,7 @@ import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration import com.uchuhimo.konf.Config import com.uchuhimo.konf.source.yaml import dev.kord.common.entity.Snowflake +import io.github.oshai.kotlinlogging.KotlinLogging import kotlinx.coroutines.runBlocking import kotlin.io.path.Path @@ -60,9 +61,12 @@ class Main : CliktCommand() { envvar = "VCSKT_ENCODING_QUALITY" ).int().restrictTo(1..10) + private val logger = KotlinLogging.logger {} + override fun run() { - // Options > Config > Default + logger.info { "Starting VCSpeaker..." } + // Options > Config > Default val config = Config { addSpec(TokenSpec) addSpec(EnvSpec) diff --git a/src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt b/src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt index 875f1572..92746791 100644 --- a/src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt +++ b/src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt @@ -1,5 +1,6 @@ package com.jaoafa.vcspeaker.tools +import io.github.oshai.kotlinlogging.KotlinLogging import io.ktor.client.* import io.ktor.client.engine.cio.* import io.ktor.client.request.* @@ -12,8 +13,10 @@ data class EmojiData( ) object Emoji { + private val logger = KotlinLogging.logger {} + private var emojis = runBlocking { - println("Loading emoji data...") + logger.info { "Loading emojis..." } val client = HttpClient(CIO) @@ -29,7 +32,7 @@ object Emoji { EmojiData(emoji, name) } - println("Loaded emoji data.") + logger.info { "Loading emojis complete." } emojiData } diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 00000000..28f8a920 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file