timberkt

Easy Android logging with Kotlin and Timber

License

License

GroupId

GroupId

com.github.ajalt
ArtifactId

ArtifactId

timberkt
Last Version

Last Version

1.5.1
Release Date

Release Date

Type

Type

aar
Description

Description

timberkt
Easy Android logging with Kotlin and Timber
Project URL

Project URL

https://github.com/ajalt/timberkt
Source Code Management

Source Code Management

https://github.com/ajalt/timberkt

Download timberkt

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ajalt/timberkt/ -->
<dependency>
    <groupId>com.github.ajalt</groupId>
    <artifactId>timberkt</artifactId>
    <version>1.5.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.ajalt/timberkt/
implementation 'com.github.ajalt:timberkt:1.5.1'
// https://jarcasting.com/artifacts/com.github.ajalt/timberkt/
implementation ("com.github.ajalt:timberkt:1.5.1")
'com.github.ajalt:timberkt:aar:1.5.1'
<dependency org="com.github.ajalt" name="timberkt" rev="1.5.1">
  <artifact name="timberkt" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.ajalt', module='timberkt', version='1.5.1')
)
libraryDependencies += "com.github.ajalt" % "timberkt" % "1.5.1"
[com.github.ajalt/timberkt "1.5.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.2.50
com.jakewharton.timber : timber jar 4.7.0

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
com.nhaarman : mockito-kotlin jar 1.5.0
org.assertj : assertj-core jar 3.9.1
org.robolectric : robolectric jar 3.8

Project Modules

There are no modules declared in this project.

Kotlin logging extensions for Timber

Jake Wharton's Timber library is great. It's a Java library with an API that works well for Java, but that isn't as idiomatic when used in Kotlin.

This library builds on Timber with an API that's easier to use from Kotlin. Instead of using formatting parameters, you pass a lambda that is only evaluated if the message is logged.

Usage

  1. Configure any Tree instances in your Application's onCreate, the same way as with plain Timber.
  2. Call the extension functions from anywhere in your code.
// Standard timber
Timber.d("%d %s", intVar + 3, stringFun())

// Kotlin extensions
Timber.d { "${intVar + 3} ${stringFun()}" }
// or
d { "${intVar + 3} ${stringFun()}" }

The same message and tags will be logged in all three cases.

The Kotlin extensions have the advantage of being more convenient to write, and are also more performant in some circumstances. The passed block is only evaluated if the message is logged, and even if the message is logged to multiple trees, the block is only evaluated once. All extension methods are inlined, so there is no method count penalty to using this library.

Logging exception objects works the same way:

// Standard timber
Timber.e(exception, "%d exceptions", errorCount)

// Kotlin extensions
Timber.e(exception) { "$errorCount exceptions" }
// or
e(exception) { "$errorCount exceptions" }

What about Timber's custom lint checks?

Timber comes with half a dozen lint checks that help you spot incorrect usage of the log calls.

With the exception of long custom tags, none of the errors those checks look for are possible with this library. You can perform arbitrary code inside of the lambdas passed to the log extensions, and there's no risk of performance problems in your release code since the blocks won't be evaluated unless the messages are printed.

Download

The Kotlin extensions for Timber are distributed with Maven Central, JCenter and JitPack.

implementation 'com.github.ajalt:timberkt:1.5.1'

Documentation

The documentation is hosted online here.

License

Copyright 2017-2018 AJ Alt

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.

Versions

Version
1.5.1