feat(connector): add logging with KotlinLogger and reload4j

This commit is contained in:
Anthony Berg 2024-05-03 01:13:16 +01:00
parent 9482ba3d97
commit 62e9267775
5 changed files with 33 additions and 7 deletions

View File

@ -11,6 +11,8 @@ val voyagerVersion = "1.0.0"
val kotlinxVersion = "1.8.0"
val koinVersion = "3.5.3"
val kodeinVersion = "7.21.2"
val kotlinLogging = "5.1.0"
val sl4jVersion = "2.0.13"
// Testing Versions
val jupyterVersion = "5.10.1"
@ -62,6 +64,11 @@ kotlin {
implementation("cafe.adriel.voyager:voyager-koin:$voyagerVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$kotlinxVersion")
// Kotlin Logging
implementation("io.github.oshai:kotlin-logging-jvm:$kotlinLogging")
implementation("org.slf4j:slf4j-api:$sl4jVersion")
implementation("org.slf4j:slf4j-reload4j:$sl4jVersion")
}
// Testing

View File

@ -0,0 +1,9 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# Print only messages of level WARN or above in the package com.foo.
log4j.logger.com.foo=WARN

View File

@ -4,12 +4,15 @@ import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import io.anthonyberg.connector.shared.ProjectTransaction
import io.anthonyberg.connector.shared.entity.Project
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.launch
class ProjectsScreenModel (
private val db: ProjectTransaction
) : StateScreenModel<ProjectState>(ProjectState.Loading) {
private val logger = KotlinLogging.logger {}
fun projectExists() {
screenModelScope.launch {
mutableState.value = ProjectState.Loading
@ -27,7 +30,7 @@ class ProjectsScreenModel (
private fun getProjects(): List<Project> {
val projects = db.getProjects()
println(projects)
logger.debug { "Loaded projects from database: $projects" }
return projects
}

View File

@ -18,11 +18,13 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.koin.getScreenModel
import io.anthonyberg.connector.shared.entity.Action
import io.github.oshai.kotlinlogging.KotlinLogging
class TestRun (
private val actions: List<Action>
) : Screen {
private val logger = KotlinLogging.logger {}
private var tested = mutableStateListOf<Boolean>()
@Composable
@ -40,30 +42,35 @@ class TestRun (
}
when (val s = state) {
is TestState.Init -> println("Loading Simulator Tests")
is TestState.Init -> logger.info { "Loading Simulator Tests" }
is TestState.NoSimulator -> {
running = false
logger.warn { "Could not connect to the simulator" }
Text("Could not connect to the simulator!")
return
}
is TestState.Ready -> {
println("Loaded Simulator Tests")
logger.info { "Loaded Simulator Tests" }
screenModel.runAction(actions[step])
}
is TestState.Running -> println("Running Action: ${s.step}")
is TestState.Running -> logger.info { "Running Action: ${s.step}" }
is TestState.Complete -> {
logger.info { "Completed test for action: ${s.step}" }
tested.add(s.pass)
step += 1
if (step == actions.size) {
logger.info { "Completed all tests" }
screenModel.end()
} else {
screenModel.runAction(actions[step])
}
}
is TestState.Idle -> running = false
is TestState.Error -> return Text("An error occurred!")
is TestState.Error -> {
logger.error { "An error occurred!" }
return Text("An error occurred!")
}
}
Column(

View File

@ -9,7 +9,7 @@ val coroutinesVersion = "1.8.0"
val ktorVersion = "2.3.9"
val sqlDelightVersion = "2.0.2"
val dateTimeVersion = "0.5.0"
val sl4jVersion = "2.0.12"
val sl4jVersion = "2.0.13"
val vdmjVersion = "4.5.0"
// Testing Dependencies