From 2ba4121a3665a9f2326cd6b9c4bff981d5cb0b3e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 4 Dec 2020 17:34:12 +0300 Subject: [PATCH] Logging moved to extensions --- CHANGELOG.md | 2 ++ .../kotlin/hep/dataforge/context/Context.kt | 16 -------------- .../kotlin/hep/dataforge/context/logging.kt | 21 ++++++++++++++++++ .../kotlin/hep/dataforge/provider/Path.kt | 22 +++++++++++++++++-- 4 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 dataforge-context/src/commonMain/kotlin/hep/dataforge/context/logging.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a543111..2e83f215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,14 @@ ## [Unreleased] ### Added - Yaml meta format based on yaml.kt +- `Path` builders ### Changed - `ListValue` and `DoubleArrayValue` implement `Iterable`. - Changed the logic of `Value::isList` to check for type instead of size - `Meta{}` builder made inline - Moved `Envelope` builder to a top level function. Companion invoke is deprecated. +- Context logging moved to the extension ### Deprecated diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Context.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Context.kt index 605e6f8b..1646d45c 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Context.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Context.kt @@ -5,13 +5,10 @@ import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaRepr import hep.dataforge.meta.sequence import hep.dataforge.names.Name -import hep.dataforge.names.plus import hep.dataforge.provider.Provider import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob -import mu.KLogger -import mu.KotlinLogging import kotlin.coroutines.CoroutineContext /** @@ -40,11 +37,6 @@ public open class Context( Laminate(meta, parent.properties) } - /** - * Context logger - */ - public val logger: KLogger = KotlinLogging.logger(name.toString()) - /** * A [PluginManager] for current context */ @@ -106,12 +98,4 @@ public interface ContextAware { * @return */ public val context: Context - - public val logger: KLogger - get() = if (this is Named) { - KotlinLogging.logger((context.name + this.name).toString()) - } else { - context.logger - } - } \ No newline at end of file diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/logging.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/logging.kt new file mode 100644 index 00000000..87ad9dbe --- /dev/null +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/logging.kt @@ -0,0 +1,21 @@ +package hep.dataforge.context + +import hep.dataforge.provider.Path +import mu.KLogger +import mu.KotlinLogging + +/** + * The logger specific to this context + */ +public val Context.logger: KLogger get() = KotlinLogging.logger(name.toString()) + +/** + * The logger + */ +public val ContextAware.logger: KLogger + get() = if (this is Named) { + KotlinLogging.logger(Path(context.name, this.name).toString()) + } else { + context.logger + } + diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/provider/Path.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/provider/Path.kt index 6cd0d7fa..77f05771 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/provider/Path.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/provider/Path.kt @@ -47,7 +47,7 @@ public inline class Path(public val tokens: List) : Iterable): Path = Path(tokens.map { PathToken(it.first, it.second) }) \ No newline at end of file