-
Notifications
You must be signed in to change notification settings - Fork 7
Getting started
Getting lumberjack to work is easy, following minimal setup is enough:
// 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 ));
-
GENERAL
All setup classes are build with a builder style, they offer methods of the typebuilder.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 booleancombineTags
which 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 booleanwithLink
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 aFileLoggingSetup
, 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 aNotificationLoggingSetup
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