Skip to content
forked from ummarbhutta/logger

✔️ Simple, pretty and powerful logger for android

License

Notifications You must be signed in to change notification settings

lupaulus/logger

 
 

Repository files navigation

Maintenance Discord Android CI codecov

Logger

Simple, pretty and powerful logger for android (Java8)

Forked project from Orhan Obut project

Setup

  1. Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency
implementation 'com.github.lupaulus:logger:2.3.2'

Into code

Initialize

Logger.addLogAdapter(new AndroidLogAdapter());

And use

Logger.d("hello");

Output

Options

Logger.d("debug");
Logger.e("error");
Logger.w("warning");
Logger.v("verbose");
Logger.i("information");
Logger.wtf("What a Terrible Failure");

String format arguments are supported

Logger.d("hello %s", "world");

Collections are supported (only available for debug logs)

Logger.d(MAP);
Logger.d(SET);
Logger.d(LIST);
Logger.d(ARRAY);

Json and Xml support (output will be in debug level)

Logger.json(JSON_CONTENT);
Logger.xml(XML_CONTENT);

Advanced

FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
  .showThreadInfo(false)  // (Optional) Whether to show thread info or not. Default true
  .methodCount(0)         // (Optional) How many method line to show. Default 2
  .methodOffset(7)        // (Optional) Hides internal method calls up to offset. Default 5
  .logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
  .tag("My custom tag")   // (Optional) Global tag for every log. Default PRETTY_LOGGER
  .build();

Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));

Loggable

Log adapter checks whether the log should be printed or not by checking this function. If you want to disable/hide logs for output, override isLoggable method. true will print the log message, false will ignore it.

Logger.addLogAdapter(new AndroidLogAdapter() {
  @Override public boolean isLoggable(int priority, String tag) {
    return BuildConfig.DEBUG;
  }
});

Save logs to the file

For now, only the CSV Format is supported !

// Local App folder in Android/data/{package_name}
File logsFolder = new File(context.getExternalFilesDir(null));
int maxBytesSize = 5000;
Logger.addLogAdapter(new DiskLogAdapter(logsFolder,maxBytesSize));

How it works

More

  • Use filter for a better result. PRETTY_LOGGER or your custom tag
  • Make sure that wrap option is disabled
  • You can also simplify output by changing settings.

  • Timber Integration
// Set methodOffset to 5 in order to hide internal method calls
Timber.plant(new Timber.DebugTree() {
  @Override protected void log(int priority, String tag, String message, Throwable t) {
    Logger.log(priority, tag, message, t);
  }
});

About

✔️ Simple, pretty and powerful logger for android

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 63.4%
  • Kotlin 36.6%