Skip to content

Custom Timber tree implementation that can save logs to SQLite

License

Notifications You must be signed in to change notification settings

pecet86/historian

 
 

Repository files navigation

Historian

Android Arsenal codecov License PRs Welcome

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

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
  def historian_version = '<version>'
  implementation "com.github.pecet86.historian:historian-core:$historian_version"
  implementation "com.github.pecet86.historian:historian-tree:$historian_version" //connect to timber
  implementation "com.github.pecet86.historian:historian-uncaught-handler:$historian_version" //crash activity
  implementation "com.github.pecet86.historian:historian-uncaught-rxjava2:$historian_version" //RaJava2 global error
  implementation "com.github.pecet86.historian:historian-uncaught-rxjava3:$historian_version" //RaJava3 global error
  implementation 'com.jakewharton.timber:timber:5.0.1'
}

android {
  buildFeatures {
    dataBinding true
    viewBinding true
  }
}

Usage

class App extends Application {

  private Historian historian;

  @Override
  public void onCreate() {
    super.onCreate();

    historian = Historian
        .builder(this)
        .debug(true)
        .logLevel(Log.INFO) //minimal log lever
        .notification(true) //show notification
        .retentionPeriod(Period.ONE_WEEK) //when delete old
        .callbacks(new Historian.Callbacks() { //added
          @Override
          public void onSuccess() {
            //is added to datebase
          }

          @Override
          public void onFailure(Throwable throwable) {
            //is error to datebase
          }
        })
        .build();

    //CrashActivity
    HistorianUncaughtExceptionHandler.install(this, historian,
        new CrashConfig()
            .withRestartActivityEnable(true)
            .withCloseActivityEnable(true)
            .withImagePath(R.drawable.historian_cow_error)

            .withRestartActivityClass(MainActivity.class)
    );

    //Global onError
    HistorianRxJava2ExceptionHandler.install(
        HistorianUncaughtExceptionHandler.getInstance()
    );
    HistorianRxJava3ExceptionHandler.install(
        HistorianUncaughtExceptionHandler.getInstance()
    );

    Timber.plant(new Timber.DebugTree());
    //install to Timber
    Timber.plant(HistorianTree.with(historian));
  }
}

Libraries definition

License

Copyright 2017 Shimizu Yasuhiro (yshrsmz)
Copyright 2020-2022 Paweł Cal (pecet86)

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.