Skip to content

Commit

Permalink
protect logger & make printlogger KMP
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Aug 31, 2023
1 parent 1b510c3 commit f7bfc76
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:OptIn(KoinInternalApi::class)

package org.koin.android.ext.koin

import android.app.Application
Expand All @@ -39,8 +41,6 @@ import java.util.*
* Setup Android Logger for Koin
* @param level
*/
@OptIn(KoinInternalApi::class)

fun KoinApplication.androidLogger(
level: Level = Level.INFO,
): KoinApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import org.koin.core.Koin
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.component.getScopeName
import org.koin.core.scope.Scope
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

//TODO Deprecate
@OptIn(KoinInternalApi::class)
class LifecycleViewModelScopeDelegate(
private val lifecycleOwner: ComponentActivity,
private val koin : Koin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.junit.Assert.assertTrue
import org.junit.Test
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.logger.EmptyLogger
import org.koin.core.logger.PrintLogger
import org.koin.dsl.koinApplication
import org.koin.dsl.module
import org.koin.test.KoinTest
Expand All @@ -16,6 +18,7 @@ import org.mockito.Mockito.mock
/**
* Android Module Tests
*/
@OptIn(KoinInternalApi::class)
class AndroidModuleTest : KoinTest {

companion object {
Expand Down Expand Up @@ -95,6 +98,6 @@ class AndroidModuleTest : KoinTest {
modules(SampleModule)
}.koin

assertTrue(koin.logger is EmptyLogger)
assertTrue(koin.logger is PrintLogger)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.koin.core.logger.Logger
import org.koin.core.logger.MESSAGE
import org.koin.core.registry.saveProperties

@OptIn(KoinInternalApi::class)
class KoinExtTest {

@Test
Expand Down
3 changes: 3 additions & 0 deletions core/koin-core/src/commonMain/kotlin/org/koin/core/Koin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import org.koin.core.component.getScopeName
import org.koin.core.error.ScopeNotCreatedException
import org.koin.core.extension.ExtensionManager
import org.koin.core.logger.EmptyLogger
import org.koin.core.logger.Level
import org.koin.core.logger.Logger
import org.koin.core.logger.PrintLogger
import org.koin.core.module.Module
import org.koin.core.module.flatten
import org.koin.core.parameter.ParametersDefinition
Expand Down Expand Up @@ -59,6 +61,7 @@ class Koin {
@KoinInternalApi
val extensionManager = ExtensionManager(this)

@KoinInternalApi
var logger: Logger = EmptyLogger()
private set

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.koin.core.logger

/**
* Multiplatform Basic Logger
*
* @author Arnaud Giuliani
*/
expect class PrintLogger(level: Level = Level.INFO) : Logger
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.koin.core.registry

import org.koin.core.Koin
import org.koin.core.annotation.KoinInternalApi
import org.koin.mp.KoinPlatformTools

/**
Expand All @@ -24,6 +25,7 @@ import org.koin.mp.KoinPlatformTools
*
* @author Arnaud Giuliani
*/
@OptIn(KoinInternalApi::class)
@Suppress("UNCHECKED_CAST")
class PropertyRegistry(internal val _koin: Koin) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.koin.dsl

import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.error.KoinAppAlreadyStartedException
Expand All @@ -12,6 +13,7 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.fail

@OptIn(KoinInternalApi::class)
class KoinAppCreationTest {

@AfterTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.koin.core.logger
* Logger that print on system.out
* @author - Arnaud GIULIANI
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {
actual class PrintLogger actual constructor(level: Level) : Logger(level) {

override fun display(level: Level, msg: MESSAGE) {
println("[$level] $KOIN_TAG $msg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.koin.core.logger
* Logger that print on system.out
* @author - Arnaud GIULIANI
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {
actual class PrintLogger actual constructor(level: Level) : Logger(level) {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@file:OptIn(KoinInternalApi::class)

package org.koin.core.registry

import org.koin.core.Koin
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.error.NoPropertyFileFoundException
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.koin.core

import org.junit.Test
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.logger.Level

@OptIn(KoinInternalApi::class)
class DebugLogTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.koin.core.logger
* Logger that print on system.out
* @author - Arnaud GIULIANI
*/
class PrintLogger(level: Level = Level.INFO) : Logger(level) {
actual class PrintLogger actual constructor(level: Level) : Logger(level) {

override fun display(level: Level, msg: MESSAGE) {
println("[$level] $KOIN_TAG $msg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.junit.rules.TestRule
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import org.koin.core.Koin
import org.koin.core.annotation.KoinInternalApi
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.dsl.KoinAppDeclaration
Expand All @@ -30,6 +31,7 @@ import org.koin.mp.KoinPlatformTools
* @author Nick Cipollo
* @author Jan Mottl
*/
@OptIn(KoinInternalApi::class)
class KoinTestRule private constructor(private val appDeclaration: KoinAppDeclaration) : TestWatcher() {

private var _koin: Koin? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
@file:Suppress("UNUSED_PARAMETER")
@file:OptIn(KoinInternalApi::class)

package org.koin.test.check

Expand Down

0 comments on commit f7bfc76

Please sign in to comment.