Skip to content

Getting started

MFlisar edited this page Mar 1, 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, null));
Timber.plant(new FileLoggingTree(true, fileLoggingSetup, null));
Timber.plant(new NotificationLoggingTree(context, true, notificationLoggingSetup, null));
// 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, null));

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 withLink which 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 with documentation: 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). Setup builder with documentation: NotificationLoggingSetup.java

  • OverlayLoggingTree
    Initialise a OverlayLoggingSetup and that's it. This logger needs a special permission, therefore, to avoid adding this permission in your release build, I've made a noop version for your release builds. Setup builder with documentation: OverlayLoggingSetup.java

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

Demoapp

Demo Lumberjack Setup

Clone this wiki locally