Skip to content

Commit

Permalink
logback added
Browse files Browse the repository at this point in the history
  • Loading branch information
demidko committed Jan 3, 2025
1 parent 45307e1 commit fdf430a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import org.gradle.api.JavaVersion.VERSION_21
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21

plugins {
kotlin("jvm") version "2.1.0-Beta1"
kotlin("plugin.serialization") version "2.1.0-Beta1"
kotlin("jvm") version "2.1.20-Beta1"
kotlin("plugin.serialization") version "2.1.20-Beta1"
application
}

Expand All @@ -22,6 +22,8 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:2.1.0-Beta1")
implementation("com.sksamuel.hoplite:hoplite-core:2.8.0")
implementation("com.squareup.retrofit2:retrofit:2.11.0")
implementation("org.slf4j:slf4j-api:2.0.16")
implementation("ch.qos.logback:logback-classic:1.5.15")
testImplementation("com.google.truth:truth:1.4.4")
testImplementation("io.mockk:mockk:1.13.12")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.kotlintelegrambot.entities.ChatPermissions
import com.sksamuel.hoplite.ConfigLoaderBuilder
import com.sksamuel.hoplite.ExperimentalHoplite
import com.sksamuel.hoplite.addEnvironmentSource
import org.slf4j.LoggerFactory.getLogger
import java.time.Duration
import java.time.Duration.ofMinutes
import java.time.ZoneId
Expand All @@ -28,7 +29,7 @@ open class ApplicationFactory {

init {
val duration = config.restrictionsDuration.toKotlinDuration()
println("Restrictions duration: $duration")
getLogger(javaClass).info("Using duration $duration")
}

open val restrictions = ChatPermissions(
Expand Down
57 changes: 32 additions & 25 deletions src/main/kotlin/com/github/demidko/glock/ChatOps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.kotlintelegrambot.entities.ChatPermissions
import com.github.kotlintelegrambot.entities.Message
import org.apache.commons.collections4.QueueUtils.synchronizedQueue
import org.apache.commons.collections4.queue.CircularFifoQueue
import org.slf4j.LoggerFactory
import java.time.Duration
import java.time.Duration.ofSeconds
import java.time.Instant.now
Expand All @@ -29,33 +30,39 @@ class ChatOps(
) {

init {
bot.getChat(chatId).getOrNull()?.let {
buildString {
with(it) {
append("id").append(id).append(' ')
if (firstName != null) {
append(firstName).append(' ')
}
if (lastName != null) {
append(lastName).append(' ')
}
if (username != null) {
append('@').append(username).append(' ')
}
if (inviteLink != null) {
append(inviteLink).append(' ')
}
if (bio != null) {
appendLine(bio)
}
if (description != null) {
appendLine(description)
}
if (pinnedMessage != null) {
appendLine(pinnedMessage)
val log = LoggerFactory.getLogger(javaClass)
val chat = bot.getChat(chatId).getOrNull()
if (chat == null) {
log.warn("Chat $chatId cannot be displayed")
} else {
val info =
buildString {
with(chat) {
append("id").append(id).append(' ')
if (firstName != null) {
append(firstName).append(' ')
}
if (lastName != null) {
append(lastName).append(' ')
}
if (username != null) {
append('@').append(username).append(' ')
}
if (inviteLink != null) {
append(inviteLink).append(' ')
}
if (bio != null) {
appendLine(bio)
}
if (description != null) {
appendLine(description)
}
if (pinnedMessage != null) {
appendLine(pinnedMessage)
}
}
}
}.let(::println)
log.info(info)
}
}

Expand Down

0 comments on commit fdf430a

Please sign in to comment.