Logger
Logger class with Kotlin improvements like lazy evaluation. It is backed by a logging port.
Samples
import com.hexagonkt.core.logging.logger
import com.hexagonkt.core.logging.Logger
import com.hexagonkt.core.logging.LoggingLevel.*
import com.hexagonkt.core.logging.LoggingManager
import org.junit.jupiter.api.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.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.warn(exception)
classLogger.error(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" }
// Logging level can be changed programmatically
LoggingManager.setLoggerLevel(ERROR)
LoggingManager.setLoggerLevel(classLogger, DEBUG)
LoggingManager.setLoggerLevel("com.hexagonkt", INFO)
// logger
//sampleEnd
}
Parameters
name
Logger name. It is shown in the logs messages and used for log filtering.
Constructors
Functions
Link copied to clipboard
Check if the DEBUG logging level is enabled for this logger.
Link copied to clipboard
Check if the ERROR logging level is enabled for this logger.
Link copied to clipboard
Check if the INFO logging level is enabled for this logger.
Link copied to clipboard
Check if a logging level is enabled for this logger.
Link copied to clipboard
Check if the TRACE logging level is enabled for this logger.
Link copied to clipboard
Check if the WARN logging level is enabled for this logger.
Link copied to clipboard
Log a message.
fun <E : Throwable> log( level: LoggingLevel, exception: E, message: (E) -> Any?)
Content copied to clipboard
Log a message, with associated exception information.
Link copied to clipboard
Set a logging level for this logger.