Skip to content

Commit

Permalink
feat: configure logging by slf4j + log4j 2 (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuahp authored Mar 26, 2024
1 parent dbe60f2 commit 292ca3c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
build

store/
stores/
cache/
data/
logs/

config.yml
test.wav
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/jaoafa/vcspeaker/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/jaoafa/vcspeaker/tools/Emoji.kt
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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)

Expand All @@ -29,7 +32,7 @@ object Emoji {
EmojiData(emoji, name)
}

println("Loaded emoji data.")
logger.info { "Loading emojis complete." }

emojiData
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Configuration status="info">
<Appenders>
<Console name="Console">
<PatternLayout pattern="%date{HH:mm:ss.SSS} [%t] %highlight{%level} %logger{1} - %msg%n" disableAnsi="false"/>
</Console>
<RollingFile name="File"
filePattern="./logs/vcspeaker-%d{yyyy-MM-dd}.log"
immediateFlush="true">
<PatternLayout pattern="%date{yyy-MM-dd HH:mm:ss.SSS} [%t] %level %logger{1} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

0 comments on commit 292ca3c

Please sign in to comment.