Skip to the content.

Logger

License: MIT JitCI Latest Version

A tiny key-value Logger implementation for Android.

How to

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle.kts at the end of repositories:

allprojects {
    repositories {
        maven(url = "https://jitpack.io")
    }
}

Step 2. Add the dependency

dependencies {
    implementation("com.github.asherepenko:android-logger:x.y.z")
}

Features

Format

Required fields list:

Contextual Data

Depending on the context, log records may include the following fields:

Usage examples

Create or extend BaseLogger instance with LogWriter implementation:

// Create logger instance
val logger = BaseLogger(
    BuildConfig.APPLICATION_ID,
    object : LogWriter() {
        override fun write(logLevel: LogLevel, logContext: LogContext) {
            val tag = extendedContext[BaseLoggerParams.TAG]
            val message = extendedContext[BaseLoggerParams.MESSAGE]

            val contextString = extendedContext.entries.joinToString()

            when (logLevel) {
                LogLevel.DEBUG -> Log.d(tag, "$message \n Context: $contextString")
                LogLevel.INFO -> Log.i(tag, "$message \n Context: $contextString")
                LogLevel.WARNING -> Log.w(tag, "$message \n Context: $contextString")
                LogLevel.ERROR -> Log.e(tag, "$message \n Context: $contextString")
            }
        }

        fun forceUpload(): Completable = Completable.complete()
    })

// Write logs with Logger
logger.info("This is a test info message")