KSLog/src/commonMain/kotlin/AutoLoggers.kt

21 lines
544 B
Kotlin
Raw Normal View History

2022-06-07 15:42:19 +00:00
package dev.inmo.kslog.common
2023-11-18 11:15:23 +00:00
/**
* Creating base tag using class simple name of receiver
*
* @throws IllegalStateException If there is no opportunity to take simple name of receiver class
*/
2022-06-07 15:42:19 +00:00
val Any.logTag
get() = this::class.simpleName ?: error("Unable to retrieve log tag")
2023-11-18 11:15:23 +00:00
/**
* Creating [TagLogger] with [logTag] as base tag
*/
2022-06-08 06:59:41 +00:00
val Any.logger: KSLog
get() = TagLogger(logTag)
2022-07-30 08:15:55 +00:00
2023-11-18 11:15:23 +00:00
/**
* Creating [TagLogger] using [logger] extension property with [tagBase] as `this`
*/
2022-07-30 08:15:55 +00:00
fun taggedLogger(tagBase: Any): KSLog = tagBase.logger