https://github.com/yshrsmz/historian
Custom Timber tree implementation that can save logs to SQLite
https://github.com/yshrsmz/historian
android android-library logging sqlite sqlite-android
Last synced: 5 months ago
JSON representation
Custom Timber tree implementation that can save logs to SQLite
- Host: GitHub
- URL: https://github.com/yshrsmz/historian
- Owner: yshrsmz
- License: apache-2.0
- Created: 2017-01-19T09:15:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-21T08:03:34.000Z (over 5 years ago)
- Last Synced: 2025-03-18T08:22:18.872Z (over 1 year ago)
- Topics: android, android-library, logging, sqlite, sqlite-android
- Language: Java
- Size: 308 KB
- Stars: 24
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Historian
===
[](https://android-arsenal.com/details/1/5329)
[](https://maven-badges.herokuapp.com/maven-central/net.yslibrary.historian/historian-core)
Historian is a custom [Timber](https://github.com/JakeWharton/timber).Tree implementation that saves logs to SQLite, so that you can see/download the SQLite file later for debugging.
This library is primarily made to help debugging crash in consumers' devices.
## Requirements
- minSdk 21+
## Installation
Historian is distributed via Maven Central. [](https://maven-badges.herokuapp.com/maven-central/net.yslibrary.historian/historian-core)
```kotlin
dependencies {
implementation("net.yslibrary.historian:historian-core:0.6.0")
implementation("net.yslibrary.historian:historian-tree:0.6.0")
implementation("com.jakewharton.timber:timber:5.0.1")
}
```
Groovy DSL
```gradle
dependencies {
implementation 'net.yslibrary.historian:historian-core:0.6.0'
implementation 'net.yslibrary.historian:historian-tree:0.6.0'
implementation 'com.jakewharton.timber:timber:5.0.1'
}
```
## Usage
### Kotlin
```kotlin
class App : Application() {
lateinit var historian: Historian
override fun onCreate() {
super.onCreate()
historian = Historian(this) {
// db name. defaults to "log.db"
name = "log.db"
// a directory where the db file will be saved. defaults to `context.filesDir`.
// The directory will be created if it does not exist.
directory = File(getExternalFilesDir(null), "logs")
// max number of logs stored in db. defaults to 500
size = 500
// log level to save. defaults to Log.INFO
logLevel = Log.INFO
// enable debug logs
debug = true
// optional callbacks
onSuccess = Historian.OnSuccessCallback { /* log saved */ }
onFailure = Historian.OnFailureCallback { throwable -> /* handle error */ }
}
// initialize historian
historian.initialize()
// plant as Timber tree - using extension function
Timber.plant(historian.toTree())
// delete all saved logs
historian.delete()
// get database path
historian.dbPath()
// graceful shutdown (call from background thread)
// historian.terminateSafe()
}
}
```
Java
```java
public class App extends Application {
Historian historian;
@Override
public void onCreate() {
super.onCreate();
historian = Historian.builder(this)
// db name. defaults to "log.db"
.name("log.db")
// a directory where the db file will be saved. defaults to `context.getFilesDir()`.
// The directory will be created if it does not exist.
.directory(new File(getExternalFilesDir(null), "logs"))
// max number of logs stored in db. defaults to 500
.size(500)
// log level to save
.logLevel(Log.INFO)
.debug(true)
.build();
// initialize historian
historian.initialize();
Timber.plant(HistorianTree.with(historian));
// delete all saved logs
historian.delete();
// provide db path
historian.dbPath();
}
}
```
## Table definition
```sql
CREATE TABLE log(
id INTEGER PRIMARY KEY AUTOINCREMENT,
priority TEXT NOT NULL,
tag TEXT NOT NULL,
message TEXT NOT NULL,
created_at INTEGER NOT NULL);
```
## License
```
Copyright 2017-2025 Yasuhiro SHIMIZU (yshrsmz)
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.
```