Skip to content

Getting started

MFlisar edited this page Feb 13, 2017 · 13 revisions

Getting started

Getting lumberjack to work is easy, following minimal setup is enough:

Minimal setup

// 1) define the setups you need
FileLoggingSetup fileLoggingSetup = new FileLoggingSetup(context);
NotificationLoggingSetup notificationLoggingSetup = new NotificationLoggingSetup(iconId);
OverlayLoggingSetup overlayLoggingSetup = new OverlayLoggingSetup();

// 2) set a log message formatter
L.setLogFormatter(new DefaultLogFormatter(5, true, true));

// 3) plant the trees you need
Timber.plant(new ConsoleTree(true, true));
Timber.plant(new FileLoggingTree(true, fileLoggingSetup ));
Timber.plant(new NotificationLoggingTree(context, true, notificationLoggingSetup ));
// Attention: This tree needs an activity context! Because it will need to ask for the overlay runtime permission!
Timber.plant(new OverlayLoggingTree(context, true, overlayLoggingSetup ));

Setup explanation

  • GENERAL
    All setup classes are build with a builder style, they offer methods of the type builder.with...(...) and they are all documented in code, so for optional setups, please refer to the documentation in code!

  • Formatter
    The library comes with a default log formatter, which allows to define how the logs should be formatter. One formatter MUST be provided, an exception is thrown otherwise. The above formatter is set up in a way, that it will print arrays and collections in a pretty way and it will print the first 5 values of an array in new lines as well.

  • ConsoleTree
    No setup needed! Just pass in a boolean combineTagswhich defines, if groups will be used for filtering only or if you want to print groups in addition to the calling class name as well and the boolean withLinkwhich defines if every log messages should have a clickable link appended which will directly open the corresponding line in the corresponding class if you click on it.

  • FileLoggingTree
    Initialise a FileLoggingSetup, which will log to the apps cache directory. It creates a new file every day or after a log file has reached a predefined size and keeps a predefined number of log history files. Setup builder: FileLoggingSetup.java

  • NotificationLoggingTree
    Initialise a NotificationLoggingSetup and provide a icon id for the notification and add all groups that the notification should be able to switch through (optional).

      NotificationLoggingSetup NOTIFICATION_LOG_SETUP = new NotificationLoggingSetup(iconId)
          // optional, if you want to be able to switch through your groups in the notification
          .withFilters(LOG_GROUPS);
    

To see an example, just check out the demo app:

Demoapp

Demo Lumberjack Setup

Clone this wiki locally