Skip to content

asherepenko/archivarius-logger

Repository files navigation

Logger with Archivarius

License: MIT JitCI Latest Version

Base JSON Logger implementation for Android. Based on Logger and Archivarius.

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:archivarius-logger:x.y.z")
}

Initial setup

Archivarius has to be initialized with two strategies before any interaction:

ArchivariusStrategy.init(object : ArchivariusStrategyImpl {
    override val isInDebugMode: Boolean = true

    override val isLogcatEnabled: Boolean = true

    override val authority: String = ""

    override val rotateFilePostfix: String = ""

    override val logName: String = "log"

    override val parentLogDir: File = File("/")

    override val logUploader: LogUploader = LogUploader()

    override val logUploadWorker: Class<out ListenableWorker> = ListenableWorker::class.java
})

ArchivariusAnalytics.init(object : ArchivariusAnalyticsImpl {
    override fun reportToCrashlytics(tag: String, e: Throwable) {
    }
})

Format

Required logger fields list:

  • message
  • timestamp (RFC 3339, with fractional seconds, nanoseconds when possible)
  • log_level (one of debug, info, warning, error)
  • application_id

Contextual Data

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

  • tag
  • user_id
  • app_install_id
  • device_serial
  • device_id
  • job_id (for background tasks)
  • exception (this field might contain error stacktrace)

Usage examples

// Create logger instance
val logger = ArchivariusLogger(
    BuildConfig.APPLICATION_ID,
    Archivarius.Builder(context).build()
)

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