JakeWharton / timber

A logger with a small, extensible API which provides utility on top of Android's normal Log class.
https://jakewharton.github.io/timber/docs/5.x/
Apache License 2.0
10.41k stars 959 forks source link

Android automatic tag #348

Closed drewhamilton closed 2 years ago

drewhamilton commented 5 years ago

Implement the option of automatic tagging—similar to Timber 4 and earlier—in LogcatTree.

How it works: Instead of only accepting a String as the default tag in its constructor, LogcatTree now also accepts a () -> String. This tagResolver is invoked for each log if the explicit tag is null.

AutomaticTagResolver implements () -> String by crawling the stack trace for the appropriate class name. Its implementation is almost directly copied from the Timber 4 implementation. It includes a note in the KDocs that use in release builds is discouraged.

Happy to add tests and/or adjust the implementation/API if you accept the general premise of this PR.

drewhamilton commented 2 years ago

Closing this because Timber 5 ended up keeping the same auto-tagging functionality that Timber 4 had.