Skip to content

Getting Started

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.10.0")
        }
    }
}

For Release Builds (No-Op)

To isolate KtorMonitor from release builds, use the ktor-monitor-logging-no-op variant. This ensures the monitor code is not included in production artifact.

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
        }
    }
}
dependencies {
    debugImplementation("ro.cosminmihu.ktor:ktor-monitor-logging:1.10.0")
    releaseImplementation("ro.cosminmihu.ktor:ktor-monitor-logging-no-op:1.10.0")
}

For Android minSdk < 26, Core Library Desugaring is required.

Install Ktor Client Plugin

HttpClient {

    install(KtorMonitorLogging) {  
        sanitizeHeader { header -> header == "Authorization" }  
        filter { request -> !request.url.host.contains("cosminmihu.ro") }  
        showNotification = true  
        retentionPeriod = RetentionPeriod.OneHour
        maxContentLength = ContentLength.Default
    }
}
  • sanitizeHeader - sanitize sensitive headers to avoid their values appearing in the logs
  • filter - filter logs for calls matching a predicate.
  • showNotification - Keep track of latest requests and responses into notification. Default is true. Android and iOS only. Notifications permission needs to be granted.
  • retentionPeriod - The retention period for the logs. Default is 1h.
  • maxContentLength - The maximum length of the content that will be logged. After this, body will be truncated. Default is 250_000. To log the entire body use ContentLength.Full.