项目作者: asherepenko

项目描述 :
Base JSON Logger implementation for Android
高级语言: Kotlin
项目地址: git://github.com/asherepenko/archivarius-logger.git
创建时间: 2020-01-31T16:24:19Z
项目社区:https://github.com/asherepenko/archivarius-logger

开源协议:MIT License

下载


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:

  1. allprojects {
  2. repositories {
  3. maven(url = "https://jitpack.io")
  4. }
  5. }

Step 2. Add the dependency

  1. dependencies {
  2. implementation("com.github.asherepenko:archivarius-logger:x.y.z")
  3. }

Initial setup

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

  1. ArchivariusStrategy.init(object : ArchivariusStrategyImpl {
  2. override val isInDebugMode: Boolean = true
  3. override val isLogcatEnabled: Boolean = true
  4. override val authority: String = ""
  5. override val rotateFilePostfix: String = ""
  6. override val logName: String = "log"
  7. override val parentLogDir: File = File("/")
  8. override val logUploader: LogUploader = LogUploader()
  9. override val logUploadWorker: Class<out ListenableWorker> = ListenableWorker::class.java
  10. })
  11. ArchivariusAnalytics.init(object : ArchivariusAnalyticsImpl {
  12. override fun reportToCrashlytics(tag: String, e: Throwable) {
  13. }
  14. })

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

  1. // Create logger instance
  2. val logger = ArchivariusLogger(
  3. BuildConfig.APPLICATION_ID,
  4. Archivarius.Builder(context).build()
  5. )
  6. // Write logs with Logger
  7. logger.info("This is a test info message")