All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.de.galdigital.logger.Loggable.kt Maven / Gradle / Ivy

The newest version!
package de.galdigital.logger

import kotlin.reflect.KClass

interface Loggable {
    /**
     * The logger tag used in extension functions for the [Loggable].
     * Note that the tag length should not be more than 23 symbols.
     */
    val loggerTag: String
        get() = this::class.tag()

    fun info(message: String) {
        info(message, loggerTag)
    }

    fun debug(message: String) {
        debug(message, loggerTag)
    }

    fun error(message: String, throwable: Throwable? = null) {
        logError(message, throwable, loggerTag)
    }

    private fun KClass<*>.tag() : String {
        val tag = this.simpleName.orEmpty()
        return when {
            tag.length <= 23 -> tag
            else -> tag.substring(0, 23)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy