-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SimpleLoggerFactory and update LoggerFactory interface
Created a new SimpleLoggerFactory class to handle logger creation. Refactored LoggerFactory to be an interface and moved logger instantiation logic to SimpleLoggerFactory. Updated relevant files to reflect these changes and ensure proper logger registration and muting functionality.
- Loading branch information
1 parent
f066bec
commit 6de48e9
Showing
5 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
15 changes: 2 additions & 13 deletions
15
log4k/src/commonMain/kotlin/io/github/smyrgeorge/log4k/LoggerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,10 @@ | ||
package io.github.smyrgeorge.log4k | ||
|
||
import io.github.smyrgeorge.log4k.impl.RootLogger | ||
import io.github.smyrgeorge.log4k.impl.RootLogger.loggers | ||
import io.github.smyrgeorge.log4k.impl.SimpleLogger | ||
import io.github.smyrgeorge.log4k.impl.extensions.toName | ||
import kotlin.reflect.KClass | ||
|
||
@Suppress("unused") | ||
class LoggerFactory { | ||
interface LoggerFactory { | ||
fun getLogger(clazz: KClass<*>): Logger = getLogger(clazz.toName()) | ||
fun getLogger(name: String): Logger { | ||
val existing = loggers.get(name) | ||
if (existing != null) return existing | ||
return SimpleLogger(name, RootLogger.level).also { | ||
val muted = loggers.isMuted(name) | ||
if (muted) it.mute() | ||
loggers.register(it) | ||
} | ||
} | ||
fun getLogger(name: String): Logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
log4k/src/commonMain/kotlin/io/github/smyrgeorge/log4k/impl/SimpleLoggerFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.smyrgeorge.log4k.impl | ||
|
||
import io.github.smyrgeorge.log4k.Logger | ||
import io.github.smyrgeorge.log4k.LoggerFactory | ||
|
||
class SimpleLoggerFactory : LoggerFactory { | ||
override fun getLogger(name: String): Logger { | ||
val existing = RootLogger.loggers.get(name) | ||
if (existing != null) return existing | ||
return SimpleLogger(name, RootLogger.level).also { | ||
RootLogger.loggers.register(it) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters