Skip to content

Index

//hexagon_core/com.hexagonkt.logging/Logger

Logger

[jvm] class Logger(name: String)

Logger class with Kotlin improvements like lazy evaluation. It is backed by a SLF4J compatible logger.

Usage example:

Samples

[jvm] import com.hexagonkt.helpers.Jvm import com.hexagonkt.helpers.logger import com.hexagonkt.logging.Logger import com.hexagonkt.injection.InjectionManager import com.hexagonkt.injection.forceBind import com.hexagonkt.serialization.Json import com.hexagonkt.serialization.parse import com.hexagonkt.serialization.serialize import org.junit.jupiter.api.Test import java.time.LocalDate import java.util.* 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.helpers.logger'. It is a default logger created for the System class (same as Logger(System::class)). """ }

classLogger.trace { "Message only evaluated if trace enabled at ${Jvm.id}" } classLogger.debug { "Message only evaluated if debug enabled at ${Jvm.id}" } classLogger.warn { "Message only evaluated if warn enabled at ${Jvm.id}" } classLogger.info { "Message only evaluated if info enabled at ${Jvm.id}" }

val exception = IllegalStateException("Exception") classLogger.warn(exception) { "Warning with exception" } classLogger.error(exception) { "Error message with exception" } classLogger.error { "Error without an exception" }

classLogger.time("Logs the time used to run the following block of code") { val message = "Block of code to be timed" assert(message.isNotBlank()) }

instanceLogger.flare { "Prints a log that stands out for ease searching" } // logger //sampleEnd }

Parameters

jvm

name

Logger name. It is shown in the logs messages and used for log filtering.

Constructors

Logger [jvm] fun Logger(type: KClass<*>)Logger class with Kotlin improvements like lazy evaluation.
Logger [jvm] fun Logger(name: String)Logger name.

Functions

Name Summary
debug [jvm]
Content
fun debug(message: () -> Any?)


error [jvm]
Content
fun error(message: () -> Any?)
fun <E : Throwable> error(exception: E, message: (E) -> Any?)


flare [jvm]
Content
fun flare(message: () -> Any? = { "" })


info [jvm]
Content
fun info(message: () -> Any?)


time [jvm]
Content
fun <T> time(message: Any?, block: () -> T): T
fun <T> time(message: () -> Any? = { null }, block: () -> T): T
fun time(startNanos: Long, message: () -> Any? = { "" })


trace [jvm]
Content
fun trace(message: () -> Any?)


warn [jvm]
Content
fun warn(message: () -> Any?)
fun <E : Throwable> warn(exception: E, message: (E) -> Any?)


Properties

Name Summary
name [jvm] val name: StringLogger name.

Comments