Skip to content

LensLogger is a Kotlin Multiplatform library for Android, iOS, and Desktop that logs Ktor network requests and responses, offering a built-in UI for easy in-app inspection and debugging.

License

Notifications You must be signed in to change notification settings

farhazulMullick/Lens-Logger

Repository files navigation

LensLogger

License Platform Platform Platform

LensLogger is a Kotlin Multiplatform (KMP) library for Android, iOS and Desktop that makes debugging network requests effortless. It automatically logs all Ktor network requests and responses, and provides a built-in UI to inspect these logs directly in your app. This helps you quickly identify issues and monitor network activity during development.

Features

  • ✨ Seamless integration with Ktor HTTP client
  • 📱 Works on both Android and iOS (KMP)
  • 🔍 Logs all network requests and responses
  • 🖥️ Built-in UI for real-time log inspection
  • 🛠️ Minimal setup and easy to use
  • ✨ DataStore Visualizer

Demo

Android iOS Desktop (Windows)
Lens Logger Demo Lens Logger Demo Lens Logger Demo
Lens Logger Demo

Installation

Add the LensLogger artifact to your module's commonMain dependencies:

dependencies {
    implementation("io.github.farhazulmullick:lens-logger:<version>")
}

Or add to your libs.versions.toml:

lensLoggerVersion = "<version>"
lens-logger = { module = "io.github.farhazulmullick:lens-logger", version.ref = "lensLoggerVersion" }

Usage

1. Integrate with Ktor Client

In your shared code (e.g., commonMain):

import io.github.farhazulmullick.lenslogger.*
import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.plugins.logging.*

val client = HttpClient(engine) {
    // Replace install(Logging) with this.
    // Log request/response in Logcat and LensUi as well.
    LensHttpLogger {
        level = LogLevel.ALL
        logger = object : Logger {
            override fun log(message: String) {
                Napier.d(message = message)
            }
        }
    }.also { 
        // setup up nappier logger.
        Napier.base(DebugAntilog()) 
    }
}

/******************* OR ********************/
/** Install only LensLogger **/

val client = HttpClient(engine) {
    // body 
    install(LensHttpLogger){
        level = LogLevel.ALL
    }
}

2. Setup LensApp UI

Simply wrap your app's root composable with LensApp. This will enable the LensLogger UI and log request/response in your app.

import io.github.farhazulmullick.lenslogger.ui.LensApp
import androidx.compose.ui.Modifier

LensApp(
    modifier = Modifier.fillMaxSize(), 
    // by default enabled, set to false to disable.
    showLensFAB = true,
    // Optional: For DataStore Visualizer
    dataStores = listOf(DataStores<Preferences>) 
) {
    // Your app content goes here
    App()
}

This will display your app content and allow you to open the LensLogger UI overlay for network log inspection.

Note: Make sure you have set up LensLogger with your Ktor client as shown above in your network module.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

LensLogger is a Kotlin Multiplatform library for Android, iOS, and Desktop that logs Ktor network requests and responses, offering a built-in UI for easy in-app inspection and debugging.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •