Skip to content

alexey-odintsov/Logger

Repository files navigation

Logger

KMP Logger for Desktop and Android apps.

Features

  • Multiplatform Support: Compatible with Kotlin Multiplatform (Android and JVM/Desktop).
  • Console & Logcat: Automatic integration with Android's Logcat and JVM's standard output.
  • File Logging: Easily log to a local file with configurable log levels.
  • Detailed Trace: Optionally include the class name, method name, and line number for easier debugging.
  • Simple API: Clean and familiar API for logging at different levels (v, d, i, w, e).
  • Raw Logging: Support for writing raw text strings to the log file.

Usage

Kotlin Multiplatform

Add the dependency to your commonMain source set in build.gradle.kts:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.alexey-odintsov:logger:0.0.1")
        }
    }
}

Android

Add the dependency to your app's build.gradle.kts:

dependencies {
    implementation("io.github.alexey-odintsov:logger-android:0.0.1")
}

Quick Start

1. Initialize the Logger

Before using the logger, you should initialize it. This is typically done in your Application.onCreate() on Android or at the start of your main() function for Desktop.

Log.init(
    logFileName = "path/to/logs.txt", // Optional: file path to save logs
    printToConsole = true,            // Optional: whether to print to console/logcat (default: false)
    printTraceElements = true,        // Optional: whether to include class/method/line number (default: false)
    fileLogLevel = Log.Level.DEBUG    // Optional: minimum level to save to file (default: DEBUG)
)

2. Log messages

You can log messages with different levels:

Log.v("Verbose message")
Log.d("Debug message")
Log.i("Info message")
Log.w("Warning message")
Log.e("Error message")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages