Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Configure logging
Browse files Browse the repository at this point in the history
  • Loading branch information
agile-jordi committed Apr 29, 2023
1 parent a685bdc commit 3725ab2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Dependencies.hikariCp
import Dependencies.kotestRunnerJunit
import Dependencies.ktorServerNetty
import Dependencies.postgresql
import Dependencies.slf4jProvider
import Dependencies.suspendApp
import Dependencies.suspendAppKtor

Expand All @@ -14,6 +15,7 @@ application {
}

dependencies {
implementation(slf4jProvider)
implementation(postgresql)
implementation(ktorServerNetty)
implementation(project(":db"))
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/kotlin/com/agilogy/timetracking/ApiServer.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.agilogy.timetracking

import arrow.continuations.SuspendApp
import arrow.continuations.ktor.server
import arrow.fx.coroutines.resourceScope
import com.agilogy.timetracking.driveradapters.httpapi.TimeTrackingApi
import io.ktor.server.netty.Netty
import kotlinx.coroutines.awaitCancellation
import kotlin.time.Duration.Companion.seconds

fun main() = SuspendApp {
resourceScope {
val timeTrackingApi = TimeTrackingApi(timeTrackingApp())
server(Netty, port = 8080, host = "0.0.0.0", preWait = 5.seconds) {
timeTrackingApi.routes()
}
awaitCancellation()
fun main() = App {
val timeTrackingApi = TimeTrackingApi(timeTrackingApp())
server(Netty, port = 8080, host = "0.0.0.0", preWait = 5.seconds) {
timeTrackingApi.routes()
}
awaitCancellation()
}
23 changes: 23 additions & 0 deletions app/src/main/kotlin/com/agilogy/timetracking/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.agilogy.timetracking

import arrow.continuations.SuspendApp
import arrow.fx.coroutines.ResourceScope
import arrow.fx.coroutines.resourceScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import java.util.logging.LogManager
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration

fun App(
context: CoroutineContext = Dispatchers.Default,
timeout: Duration = Duration.INFINITE,
block: suspend context(CoroutineScope, ResourceScope) () -> Unit,
) = SuspendApp(context, timeout) {
this.javaClass.getResourceAsStream("/logging.properties").use {
LogManager.getLogManager().readConfiguration(it)
}
resourceScope {
block(this@SuspendApp, this)
}
}
8 changes: 2 additions & 6 deletions app/src/main/kotlin/com/agilogy/timetracking/ConsoleApp.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.agilogy.timetracking

import arrow.continuations.SuspendApp
import arrow.fx.coroutines.resourceScope
import com.agilogy.timetracking.driveradapters.console.ConsoleAdapter

fun main(args: Array<String>): Unit = SuspendApp {
resourceScope {
ConsoleAdapter(timeTrackingApp()).main(args)
}
fun main(args: Array<String>): Unit = App {
ConsoleAdapter(timeTrackingApp()).main(args)
}

7 changes: 7 additions & 0 deletions app/src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
handlers= java.util.logging.ConsoleHandler
.level= INFO
com.zaxxer.hikari.level= WARNING

java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = [%1$tF %1$tT] [%4$-7s] %5$s%n
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ object Dependencies {
val zaxxer = "com.zaxxer"
val hikariCpVersion = "5.0.1"
val hikariCp = "$zaxxer:HikariCP:$hikariCpVersion"

val slf4jVersion = "2.0.7"
val slf4jProvider = "org.slf4j:slf4j-jdk14:$slf4jVersion"
}
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ val libs = File("${rootDir}/libs/").listFiles()!!.filter { it.isDirectory }.map
libs.forEach { configureProject(it, "libs") }

fun configureProject(name: String, path: String) {
println("Configuring project $name with path $path")
include(":$name")
project(":$name").projectDir = File("$path/$name")
}
Expand Down

0 comments on commit 3725ab2

Please sign in to comment.