
Logging library enables structured logging with features like multi-line message handling, customizable timestamp formatting, and logging group mechanisms. Supports file outlets and log rotation.
Kotlin/Multiplatform logging library.
// Logbook.WithDefaults gives us default log levels, formatting, and a console outlet:
class ParserLog : Logbook.WithDefaults() {
// the logger's name is inferred as "Parser" but can be overridden:
// override val name = "Parsing"
// declare a new log level that is lower than debug:
val trace by level(placeBefore = debug) {
colorInfo = ColorInfo(0x999999) // gray
}
// set the format of the logger, example output: 2025-02-04T20:46:55Z Parser - warning : something happened!!
override fun format(entry: LogEntry) =
StartChunks + entry.time.utc.formatAsStandard() + " " + entry.logbook + " - " + entry.level + " : " + data.toString() + EndChunks
// set the minimum log level to trace:
init {
minimumLevel = trace
}
// add companion object to avoid having to manually construct instance:
companion object : ParserLog()
}Simply add a dependency on logbook to your Gradle project:
repositories {
mavenCentral()
}
// for Kotlin/Multiplatform projects:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("moe.micha:logbook:$version")
}
}
}
// for Kotlin/JVM projects:
kotlin {
dependencies {
implementation("moe.micha:logbook:$version")
}
}Replace $version with the version you want, a list of which can be retrieved on
Maven Central.
I would love for people to contribute to logbook!
If you feel like the library is missing something or you've encountered a bug, please let me know with a GitHub Issue! No need to be shy, there is no format to these Issues, just type whatever you want :)
If you've already got experience with Kotlin, feel free to work on a fix or feature on your own and submitting a Pull Request! There are no official contribution guidelines, just try your best and I'll see if I can fix some issues if there are any :)
console.group).
groupImplicitly and groupExplicitly.
groupExplicitly would take a block in which a sublogger is accessible, which prints to the group.
groupImplicitly would cause all following calls to the logger to be treated as though they were done on a sublogger.
Just some ideas.Kotlin/Multiplatform logging library.
// Logbook.WithDefaults gives us default log levels, formatting, and a console outlet:
class ParserLog : Logbook.WithDefaults() {
// the logger's name is inferred as "Parser" but can be overridden:
// override val name = "Parsing"
// declare a new log level that is lower than debug:
val trace by level(placeBefore = debug) {
colorInfo = ColorInfo(0x999999) // gray
}
// set the format of the logger, example output: 2025-02-04T20:46:55Z Parser - warning : something happened!!
override fun format(entry: LogEntry) =
StartChunks + entry.time.utc.formatAsStandard() + " " + entry.logbook + " - " + entry.level + " : " + data.toString() + EndChunks
// set the minimum log level to trace:
init {
minimumLevel = trace
}
// add companion object to avoid having to manually construct instance:
companion object : ParserLog()
}Simply add a dependency on logbook to your Gradle project:
repositories {
mavenCentral()
}
// for Kotlin/Multiplatform projects:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("moe.micha:logbook:$version")
}
}
}
// for Kotlin/JVM projects:
kotlin {
dependencies {
implementation("moe.micha:logbook:$version")
}
}Replace $version with the version you want, a list of which can be retrieved on
Maven Central.
I would love for people to contribute to logbook!
If you feel like the library is missing something or you've encountered a bug, please let me know with a GitHub Issue! No need to be shy, there is no format to these Issues, just type whatever you want :)
If you've already got experience with Kotlin, feel free to work on a fix or feature on your own and submitting a Pull Request! There are no official contribution guidelines, just try your best and I'll see if I can fix some issues if there are any :)
console.group).
groupImplicitly and groupExplicitly.
groupExplicitly would take a block in which a sublogger is accessible, which prints to the group.
groupImplicitly would cause all following calls to the logger to be treated as though they were done on a sublogger.
Just some ideas.