logger README

The project's README from github.com/orhanobut/logger. As one markdown file: README.md.

Logger

Logger logo

Readable, structured logs for Android. Turn messages, collections, JSON, and XML into output that's easy to scan in Logcat.

Example Logcat output

Setup

Add Google Maven and Maven Central to your dependency repositories:

dependencyResolutionManagement {
  repositories {
    google()
    mavenCentral()
  }
}
dependencies {
  implementation("com.orhanobut:logger:2.2.0")
}

Initialize once in your application, then log:

Logger.addLogAdapter(AndroidLogAdapter())
Logger.d("hello %s", "world")

Messages

Logger.d("debug")
Logger.e("error")
Logger.w("warning")
Logger.v("verbose")
Logger.i("information")
Logger.wtf("What a Terrible Failure")

Logger.d("hello %s", "world")
Logger.d(listOf("foo", "bar"))
Logger.d(mapOf("key" to "value"))
Logger.d(intArrayOf(1, 2, 3))
Logger.json("""{"items":[1,2,3]}""")
Logger.xml("<root><item>value</item></root>")

Collection and structured output use debug priority. Include an exception and its cause with Logger.e(throwable, "message").

Set a tag for exactly one message on the calling thread:

Logger.t("Checkout").d("Order submitted")

Formatting and filtering

val format = PrettyFormatStrategy.newBuilder()
  .showThreadInfo(false) // Default: true
  .methodCount(0)        // Default: 2 caller frames
  .methodOffset(0)       // Default: 0 additional frames skipped
  .tag("MyApp")          // Default: PRETTY_LOGGER
  .build()

Logger.addLogAdapter(object : AndroidLogAdapter(format) {
  override fun isLoggable(priority: Int, tag: String?): Boolean = BuildConfig.DEBUG
})

Logger.t("Screen").d("A message tagged MyApp-Screen")

Override LogAdapter.isLoggable to filter messages by priority or tag. The example above enables logging only in debug builds. Use Logger.clearLogAdapters() before replacing the configured adapters.

For Logcat filtering, use PRETTY_LOGGER or your configured tag.

File logging

Save formatted logs to app-private storage with CsvFormatStrategy and a custom DiskLogStrategy. The sample shows the complete setup, including background writes and cleanup. App-private storage requires no storage permission.

The default DiskLogAdapter() still uses the legacy shared external-storage location. Modern Android restricts that location through scoped storage; use the sample's custom strategy for current applications.

Timber integration

Timber.plant(object : Timber.DebugTree() {
  override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
    Logger.log(priority, tag, message, t)
  }
})

License

Apache License 2.0

logger (orhanobut/logger)

Searching Database…

13.8K ·GitHub
What is this?Logger is a simple, pretty, and powerful logging library for Android that makes Logcat output easier to read.
Is this a standalone app or a library I add to an Android project?It's an Android/Java/Kotlin library you include as a dependency and initialize in your app code — it has no UI or app of its own.
How do I add it to my Android project?Download the library (add it as a dependency), initialize Logger once in your app, then call its log methods wherever you want formatted output.
How is Logger's output different from plain Android Log calls?Based on its GitHub topics ('pretty-printer', 'json-logging'), Logger formats output with structured borders and can pretty-print JSON, making logs much easier to scan in Logcat than raw Log.d output.
Is it similar to Jake Wharton's Timber library?The repo lists 'timber' as a related topic, suggesting Logger plays a similar role — a drop-in wrapper over Android's Log class — but with an emphasis on pretty-printed and JSON-formatted output.
Does it work for both Java and Kotlin Android projects?Yes, the library itself is written in Kotlin and its topics include both 'java' and 'kotlin', so Android apps written in either language can use it.
Creator
orhanobut
Size
1.9 MB
Stars
13.8K
Age
11y
Commits · 90 Days