Giter Club home page Giter Club logo

logger's Introduction

Logger

This is a logger based on the official android.util.Log API and with some additional features:

  • Add file & line number info (e.g. MainActivity.java:15) to the log tag, which support to jump to the log line by a click.
  • Save logs to file.
  • Support formatted String directly.
  • Open/Close log messages output at runtime (using adb shell setprop log.tag.YOUR_TAG DEBUG).
  • Integrate with Timber.

With these features, the Logger can help you debugging your apps more easily.

Gradle

dependencies {
    implementation 'com.github.duanhong169:logger:${latestVersion}'
    ...
}

Replace ${latestVersion} with the latest version code. See releases.

Usage

Config Logger (optional)

Use the static methods to config Logger if needed:

Logger.setLevel(Log.DEBUG);
Logger.setTagPrefix("MyApplication");
Logger.setLogFile(Environment.getExternalStorageDirectory().getPath() + "/0/dev/log");
Logger.setLogFileMaxSizeInMegabytes(10);

Print log

Logger.v("Logger: %s", variable);
Logger.d("Logger: %s", variable);
Logger.i("Logger: %s", variable);
Logger.w("Logger: %s", variable);
Logger.e("Logger: %s", variable);
Logger.wtf("Logger: %s", variable);

Integrate with Timber

private static class LoggerTree extends Timber.Tree {
    @Override
    protected void log(int priority, String tag, @NonNull String message, Throwable t) {
        Logger.logWithTimber(priority, tag, message);
    }
}

Timber.plant(new LoggerTree());

Control logcat output

Use shell commands:

adb shell setprop log.tag.MyApplication DEBUG # Open
adb shell setprop log.tag.MyApplication INFO  # Close

The setprop will override the log level config.

For more details, see the sample app.

License

See the LICENSE file.

logger's People

Contributors

duanhong169 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

linhtinh11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.