A tiny key-value Logger implementation for Android.
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")
}
Loggerdefines base context inkey-valueformatLogWriterdefines the way where to store logs- Can be easily used with Archivarius
Required fields list:
messagetimestamp(RFC 3339, with fractional seconds, nanoseconds when possible)log_level(one ofdebug,info,warning,error)application_id
Depending on the context, log records may include the following fields:
taguser_idapp_install_iddevice_serialdevice_idjob_id(for background tasks)exception(this field might contain error stacktrace)
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")