Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bastienpaulfr/Treessence
Some trees for Timber lib
https://github.com/bastienpaulfr/Treessence
Last synced: about 2 months ago
JSON representation
Some trees for Timber lib
- Host: GitHub
- URL: https://github.com/bastienpaulfr/Treessence
- Owner: bastienpaulfr
- License: apache-2.0
- Created: 2017-12-07T07:21:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-02T14:39:14.000Z (about 1 year ago)
- Last Synced: 2024-07-02T05:41:52.834Z (3 months ago)
- Language: Kotlin
- Size: 199 KB
- Stars: 96
- Watchers: 2
- Forks: 10
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - bastienpaulfr/Treessence - Some trees for Timber lib (Kotlin)
README
[![Release](https://jitpack.io/v/bastienpaulfr/Treessence.svg)](https://jitpack.io/#bastienpaulfr/Treessence)
[![Build Status](https://travis-ci.org/bastienpaulfr/Treessence.svg?branch=master)](https://travis-ci.org/bastienpaulfr/Treessence)# Treessence
Some trees for Timber lib## Set up
**build.gradle**
```
repositories {
maven { url "https://jitpack.io" }
}dependencies {
//Treessence does not include Timber
implementation 'com.jakewharton.timber:timber:5.0.1'
implementation 'com.github.bastienpaulfr:Treessence:1.1.2'
}
```### Usage
1. Checkout [Timber](https://github.com/JakeWharton/timber)
2. Add any trees you like## Essences of tree
### Console
#### ThrowErrorTree
An implementation of `Timber.Tree` which throws `Error` when priority of
log is exceeded the limit. Useful for development or test environment.```java
// Will throw an error if Timber.e() is used
Timber.plant(new ThrowErrorTree(Log.ERROR));
```#### SystemLogTree
An implementation of `Timber.Tree` which logs into `System.out`
```java
Timber.plant(new SystemLogTree());
```### File Logging
#### FileLoggerTree
An implementation of `Timber.Tree` which sends log into a circular file.
`java.util.logging.Logger` is used for logging```java
Tree t = new FileLoggerTree.Builder()
.withFileName("file%g.log")
.withDirName("my/dir")
.withSizeLimit(20000)
.withFileLimit(3)
.withMinPriority(Log.DEBUG)
.appendToFile(true)
.build();
Timber.plant(t);
```### Custom formatting
It is possible to use a custom formatter with trees.
```java
SystemLogTree tree = new SystemLogTree(Log.VERBOSE, NoFilter.INSTANCE, LogcatFormatter.INSTANCE);
```For timezone issue, a custom timezone can be set
```java
// Create object that will provide timestamp string
TimeStamper timeStamper = new TimeStamper("MM-dd HH:mm:ss:SSS", TimeZone.getTimeZone("GMT+2"))
// Set time stamper to LogcatFormatter
LogcatFormatter.INSTANCE.setTimeStamper(timeStamper);
// Formatter can be set to a Tree
[...]
```## DSL
Since version 1.0, there is a Kotlin dsl to configure Timber in Applications
### Starting Timber
```kotlin
//Create a TimberApplication to configure Timber.
startTimber {}
```
### Adding trees
```kotlin
startTimber {
// Add a Timber.DebugTree
debugTree()// Add a Tree that log only from Log.INFO level
releaseTree()// Add a simple tree with a filter and a formatter
tree(
{ s: String, t: Throwable? ->
// Log goes through this method and it is up to you to write those where you want
}
) {
level = Log.INFOfilter(NoFilter())
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a Tree that log into logcat
logcatTree {
level = Log.INFOfilter(NoFilter())
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that log into a file
fileTree {
level = Log.INFO
fileName = "myfile"
dir = temporaryFolder.newFolder().absolutePath
sizeLimit = 10
fileLimit = 1
appendToFile = truefilter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that log using System.out.print()
systemTree {
level = Log.INFOfilter(NoFilter())
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that is throwing an exception when Timber.e() is called
throwErrorTree {
level = Log.INFOfilter(NoFilter())
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that put breadcrumb into Sentry API
sentryBreadCrumbTree {
level = Log.VERBOSEfilter(TagFilter("^(?!.*(Sentry|App)).*"))
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that sends an event to sentry on each log.
sentryEventTree {
level = Log.ERRORfilter(TagFilter("^(?!.*(Sentry|App)).*"))
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}// Add a tree that is logging into a TextView
textViewTree {
level = Log.INFO
append = truefilter(NoFilter())
filter { prio, tag, m, t ->
false
}formatter { prio, tag, message ->
""
}
}
}
```### Uproot all trees
```kotlin
stopTimber()
```## Licence
Copyright [2017] Bastien PAUL
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 athttp://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.