Logging moved to extensions
This commit is contained in:
parent
eb16294a7e
commit
2ba4121a36
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public inline class Path(public val tokens: List<PathToken>) : Iterable<PathToke
|
||||
public fun parse(path: String): Path {
|
||||
val head = path.substringBefore(PATH_SEGMENT_SEPARATOR)
|
||||
val tail = path.substringAfter(PATH_SEGMENT_SEPARATOR)
|
||||
return PathToken.parse(head).toPath() + parse(tail)
|
||||
return PathToken.parse(head).asPath() + parse(tail)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,4 +72,22 @@ public data class PathToken(val name: Name, val target: String? = null) {
|
||||
}
|
||||
}
|
||||
|
||||
public fun PathToken.toPath(): Path = Path(listOf(this))
|
||||
/**
|
||||
* Represent this path token as full path
|
||||
*/
|
||||
public fun PathToken.asPath(): Path = Path(listOf(this))
|
||||
|
||||
/**
|
||||
* Represent a name with optional [target] as a [Path]
|
||||
*/
|
||||
public fun Name.asPath(target: String? = null): Path = PathToken(this, target).asPath()
|
||||
|
||||
/**
|
||||
* Build a path from given names using default targets
|
||||
*/
|
||||
public fun Path(vararg names: Name): Path = Path(names.map { PathToken(it) })
|
||||
|
||||
/**
|
||||
* Use an array of [Name]-target pairs to construct segmented [Path]
|
||||
*/
|
||||
public fun Path(vararg tokens: Pair<Name, String?>): Path = Path(tokens.map { PathToken(it.first, it.second) })
|
Loading…
Reference in New Issue
Block a user