Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 2.7 KB

README.md

File metadata and controls

74 lines (56 loc) · 2.7 KB

log4k-slf4j

Build Maven Central GitHub License GitHub commit activity GitHub issues Kotlin

A Comprehensive Logging and Tracing Solution for Kotlin Multiplatform.

This project provides a robust, event-driven logging and tracing platform specifically designed for Kotlin Multiplatform (also compatible with the Java ecosystem). Built with coroutines and channels at its core, it offers asynchronous, scalable logging across multiple platforms.

This project also tries to be fully compatible with OpenTelemetry standard.

Important

The project is in a very early stage; thus, breaking changes should be expected.

📖 Documentation

🏠 Homepage (under construction)

Usage

repositories {
    mavenCentral()
}

dependencies {
    // https://central.sonatype.com/artifact/io.github.smyrgeorge/log4k-coroutines
    implementation("io.github.smyrgeorge:log4k-coroutines:x.y.z")
}

Examples

Logger.factory = SimpleCoroutinesLoggerFactory()
val trace: Tracer = Tracer.of(this::class)
val log = Logger.of(this::class)

log.info("Hello from coroutines logger!")

val parent: TracingEvent.Span.Remote = trace.span(id = "ID_EXAMPLE", traceId = "TRACE_ID_EXAMPLE")
val ctx = LoggingContext.builder().with(parent).build()

withContext(ctx) {
    val ctx = LoggingContext.current()
    log.info("Hello from coroutines logger with context=$ctx!")

    ctx.span("span-1") {
        log.info("Hello from span '${ctx.spans.peek()?.name}'!")
        ctx.span("span-2") {
            log.info("Hello from span '${ctx.spans.peek()?.name}'!")
            ctx.span("span-3") {
                log.info("Hello from span '${ctx.spans.peek()?.name}'!")
            }
        }
    }

    log.info("Hello from coroutines logger with context=$ctx!")
}