timber README

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

Timber

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class.

I copy this class into all the little apps I make. I'm tired of doing it. Now it's a library.

Behavior is added through Tree instances. You can install an instance by calling Timber.plant. Installation of Trees should be done as early as possible. The onCreate of your application is the most logical choice.

The DebugTree implementation will automatically figure out from which class it's being called and use that class name as its tag. Since the tags vary, it works really well when coupled with a log reader like Pidcat.

There are no Tree implementations installed by default because every time you log in production, a puppy dies.

Usage

Two easy steps:

  1. Install any Tree instances you want in the onCreate of your application class.
  2. Call Timber's static methods everywhere throughout your app.

Check out the sample app in timber-sample/ to see it in action.

Lint

Timber ships with embedded lint rules to detect problems in your app.

Download

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.jakewharton.timber:timber:5.0.1'
}

Documentation is available at jakewharton.github.io/timber/docs/5.x/.

Snapshots of the development version are available in Sonatype's snapshots repository.

repositories {
  mavenCentral()
  maven {
    url 'https://central.sonatype.com/repository/maven-snapshots/'
  }
}

dependencies {
  implementation 'com.jakewharton.timber:timber:5.1.0-SNAPSHOT'
}

Snapshot documentation is available at jakewharton.github.io/timber/docs/latest/.

License

Copyright 2013 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

timber (JakeWharton/timber)

Searching Database…

10.9K ·GitHub
这是什么?Timber 是一个日志库,API 小巧且易于扩展,它构建在 Android 自带的 Log 类之上。想要增加功能时,你只需植入 Tree 实例,而不必直接调用 Log.d、Log.e。
这是独立应用,还是我可以加入项目的库?它是一个要引入 Android 应用中的库。默认不附带任何 Tree 实现,所以在你植入 Tree 之前,它不会输出任何日志。
我该怎么在应用里开始使用它?在 Application 类的 onCreate 中植入你需要的 Tree 实例(比如 DebugTree),然后在应用的任何地方调用 Timber 的静态方法(如 Timber.d、Timber.e 等)。
它能用在 Android 应用之外吗?不能。Timber 是专门为 Android 的 Log 类做的封装,因此只适用于 Android 项目。
如果我只添加依赖、不做额外设置,它会输出日志吗?不会。在你显式植入 Tree(例如 DebugTree)之前,Timber 保持静默;该库有意不默认启用任何日志 Tree。
内置的 DebugTree 做什么?DebugTree 会自动识别调用它的类,并把该类名用作日志标签,这与 Pidcat 等日志查看工具配合得很好。
TimberArgCount 这个检查项能发现什么问题?Timber 内嵌了一条 Android Lint 规则,用于标记参数个数与格式字符串中占位符数量不一致的 Timber 调用,例如给需要两个参数的字符串只传了一个参数。
为什么要用 Timber,而不直接调用 Log?Timber 提供了小巧且易于扩展的 API,日志行为通过可插拔的 Tree 类来定义,还会自动为调用添加标签,并且默认避免在正式版本中保留调试日志。
Size
2.8 MB
Stars
10.9K
Age
13y
Commits · 90 Days