Historian

Additional

Language
Java
Version
v0.4.0 (Mar 21, 2021)
Created
Jan 19, 2017
Updated
Mar 21, 2021 (Retired)
Owner
Yasuhiro SHIMIZU (yshrsmz)
Contributor
Yasuhiro SHIMIZU (yshrsmz)
1
Activity
Badge
Generate
Download
Source code

Historian

Historian is a custom 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.

Installation

Historian is distributed via Maven Central.

dependencies {
  compile 'net.yslibrary.historian:historian-core:LATEST_LIBRARY_VERSION'
  compile 'net.yslibrary.historian:historian-tree:LATEST_LIBRARY_VERSION'
  compile 'com.jakewharton.timber:timber:4.5.1'
}

Usage

class App extends Application {

    Historian historian;

    @Override
    public void onCreate() {
        historian = Historian.builder(context)
            // db name. defaults to "log.db"
            .name("log.db")
            // a directory where the db file will be saved. defaults to `context.getFiles()`.
            // The directory will be created if it does not exist.
            .directory(new File(Environment.getExternalStorageDirectory(), "somedir"))
            // 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 in Uri
        historian.dbPath();
    }
}

Table definition

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-2021 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.