Site icon Android Tutorial Online

Easy logging on Android with Kotlin context receivers

Plank

Plank is an Android library for easy logging using context receivers.

 

Flavours

There are 3 flavours to choose from:

  1. Seal:
"Logging using the «seal» flavour" log debug
  1. Func:
log("Logging using the «func» flavour")
  1. Classic:
Plank.d("Logging using the «classic» flavour")

All of the above yield the same results and the tag is inferred based on the class from which the message is logged. In this case, the only difference is syntax.

Installation

  1. Choose one flavour:
    • Seal
    implementation(“com.github.sunkengxd.plank:seal:1.0.0”)
    • Func
    implementation(“com.github.sunkengxd.plank:func:1.0.0”)
    • Classic
    implementation(“com.github.sunkengxd.plank:classic:1.0.0”)
  2. Add kotlin compiler options:
// module-level build.gradle.kts
kotlinOptions {
    // ...
    freeCompilerArgs = listOf("-Xcontext-receivers")
}

Usage

Apart from logging, the library supports muting the messages. All of the below can only be called from the Application class.

  1. Seal:
Plank.muteAll() // prevents any logging
verbose.mute() // mutes all verbose type messages
  1. Func:
PlankConfig.mute() // the same as muteAll() from seal
  1. Classic:
Plank.mute() // the same as mute() from func or muteAll() from seal

Additional parameters

Limitations

Due to the Any context receiver of these functions, they cannot be used inside top-level functions.

Feedback

Any feedback is welcome!

GitHub

View Github

Exit mobile version