KMP Logger for Desktop and Android apps.
- 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.
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")
}
}
}Add the dependency to your app's build.gradle.kts:
dependencies {
implementation("io.github.alexey-odintsov:logger-android:0.0.1")
}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)
)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")