Skip to content

Commit

Permalink
3.2.4-rc2 - Revert Logger API from "import updates from 3.5 for Scope…
Browse files Browse the repository at this point in the history
… parallele resolution fix - #1561"
  • Loading branch information
arnaudgiuliani committed Dec 29, 2023
1 parent 99eb92f commit 13893d4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ import org.koin.core.logger.MESSAGE
*/
class AndroidLogger(level: Level = Level.INFO) : Logger(level) {

override fun display(level: Level, msg: MESSAGE) {
override fun log(level: Level, msg: MESSAGE) {
if (this.level <= level) {
logOnLevel(msg, level)
}
}

private fun logOnLevel(msg: MESSAGE, level: Level) {
when (level) {
Level.DEBUG -> Log.d(KOIN_TAG, msg)
Level.INFO -> Log.i(KOIN_TAG, msg)
Level.WARNING -> Log.w(KOIN_TAG, msg)
Level.ERROR -> Log.e(KOIN_TAG, msg)
else -> Log.e(KOIN_TAG, msg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ package org.koin.core.logger
*/
class EmptyLogger : Logger(Level.NONE) {

override fun display(level: Level, msg: MESSAGE) {}
override fun log(level: Level, msg: MESSAGE) {
}
}
37 changes: 20 additions & 17 deletions core/koin-core/src/commonMain/kotlin/org/koin/core/logger/Logger.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-Present the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,39 +22,42 @@ package org.koin.core.logger
*/
abstract class Logger(var level: Level = Level.INFO) {

abstract fun display(level: Level, msg: MESSAGE)
abstract fun log(level: Level, msg: MESSAGE)

fun debug(msg: MESSAGE) {
log(Level.DEBUG, msg)
private fun canLog(level: Level): Boolean = this.level <= level

private fun doLog(level: Level, msg: MESSAGE) {
if (canLog(level)) {
log(level, msg)
}
}

fun info(msg: MESSAGE) {
log(Level.INFO, msg)
fun debug(msg: MESSAGE) {
doLog(Level.DEBUG, msg)
}

fun warn(msg: MESSAGE) {
log(Level.WARNING, msg)
fun info(msg: MESSAGE) {
doLog(Level.INFO, msg)
}

fun error(msg: MESSAGE) {
log(Level.ERROR, msg)
doLog(Level.ERROR, msg)
}

fun isAt(lvl: Level): Boolean = this.level <= lvl

fun log(lvl: Level, msg: String) {
if (isAt(lvl)) display(lvl, msg)
}

fun log(lvl: Level, msg: () -> String) {
if (isAt(lvl)) display(lvl, msg())
fun log(lvl: Level, msg : () -> String){
if (isAt(lvl)) doLog(lvl,msg())
}
}

const val KOIN_TAG = "[Koin]"

/**
* Log Level
*/
enum class Level {
DEBUG, INFO, WARNING, ERROR, NONE
DEBUG, INFO, ERROR, NONE
}

typealias MESSAGE = String
typealias MESSAGE = String
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ data class Scope(
): T {
return if (_koin.logger.isAt(Level.DEBUG)) {
val qualifierString = qualifier?.let { " with qualifier '$qualifier'" } ?: ""
_koin.logger.display(Level.DEBUG, "|- '${clazz.getFullName()}'$qualifierString ...")
_koin.logger.debug("|- '${clazz.getFullName()}'$qualifierString ...")

val start = KoinPlatformTimeTools.getTimeInNanoSeconds()
val instance = resolveInstance<T>(qualifier, clazz, parameters)
val stop = KoinPlatformTimeTools.getTimeInNanoSeconds()
val duration = (stop - start) / Timer.NANO_TO_MILLI

_koin.logger.display(Level.DEBUG, "|- '${clazz.getFullName()}' in $duration ms")
_koin.logger.debug("|- '${clazz.getFullName()}' in $duration ms")
instance
} else {
resolveInstance(qualifier, clazz, parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ package org.koin.core.logger
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {

override fun display(level: Level, msg: MESSAGE) {
println("[$level] $KOIN_TAG $msg")
override fun log(level: Level, msg: MESSAGE) {
if (this.level <= level) {
println("[$level] $KOIN_TAG $msg")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package org.koin.core.logger
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {

private val printer = if (level >= Level.WARNING) System.err else System.out

override fun display(level: Level, msg: MESSAGE) {
printer.println("[$level] $KOIN_TAG $msg")
override fun log(level: Level, msg: MESSAGE) {
if (this.level <= level) {
val printer = if (level >= Level.ERROR) System.err else System.out
printer.println("[$level] $KOIN_TAG $msg")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ package org.koin.core.logger
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {

override fun display(level: Level, msg: MESSAGE) {
println("[$level] $KOIN_TAG $msg")
override fun log(level: Level, msg: MESSAGE) {
if (this.level <= level) {
println("[$level] $KOIN_TAG $msg")
}
}
}
4 changes: 2 additions & 2 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
// Koin Versions
koin_version = '3.2.4-rc1'
koin_android_version = '3.2.4-rc1'
koin_version = '3.2.4-rc2'
koin_android_version = '3.2.4-rc2'

// Kotlin
kotlin_version = '1.6.21'
Expand Down

0 comments on commit 13893d4

Please sign in to comment.