Logger
Logger class with Kotlin usability improvements. It is backed by a System.Logger instance.
Parameters
name
Logger name. It is shown in the logs messages and used for log filtering.
Samples
import com.hexagonkt.core.text.Ansi.RESET
import com.hexagonkt.core.text.AnsiColor.BRIGHT_WHITE
import com.hexagonkt.core.text.AnsiColor.RED_BG
import com.hexagonkt.core.text.AnsiEffect.UNDERLINE
import com.hexagonkt.core.urlOf
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.condition.DisabledInNativeImage
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
import java.lang.System.Logger.Level.ERROR
import java.lang.System.Logger.Level.TRACE
import java.util.logging.LogManager
import kotlin.IllegalStateException
import kotlin.reflect.KClass
import kotlin.test.*
fun main() {
//sampleStart
// logger
val classLogger: Logger = Logger(Runtime::class) // Logger for the `Runtime` class
val instanceLogger: Logger = Logger(this::class) // Logger for this instance's class
logger.info {
"""
You can add a quick log without declaring a Logger with
'com.hexagonkt.core.logging.logger'. It is a default logger created with a custom name
(same as `Logger(LoggingManager.defaultLoggerName)`).
"""
}
classLogger.trace { "Message only evaluated if trace enabled" }
classLogger.debug { "Message only evaluated if debug enabled" }
classLogger.warn { "Message only evaluated if warn enabled" }
classLogger.info { "Message only evaluated if info enabled" }
val exception = IllegalStateException("Exception")
classLogger.warn(exception) { "Warning with exception" }
classLogger.error(exception) { "Error message with exception" }
classLogger.warn(exception)
classLogger.error(exception)
classLogger.error { "Error without an exception" }
// logger
//sampleEnd
}