BLog is not blog but an android logcat entended utility library. It helps to log message to file as well as print in logcat window.
Java
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
logger
.gitignore
.travis.yml
LICENSE
README.md
README_CN.md
bintrayUpload.gradle
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

BLog - Android Log Extended Utility

中文

BLog is an Android LogCat extended Utility. It can simplify the way you use {@link android.util.Log}, as well as write our log message into file for after support.

BLog is not pronounced 'Blog[blɒɡ]', but '[bi:lɒɡ]'.

Feature

  1. Simplified Api for logging message.
  2. Print Thread Info.
  3. Set LogLevel to control whether to print log or not.
  4. Write log message to file in order to trace bugs from release app.

Though BLog support using LogLevel to control whether to print log message or not, it is recommended to use if statement with a constant as condition to control the Log Block as the following snippet.

if (BuildConfig.DEBUG) {
  BLog.v(TAG, "Log verbose");
}

Please try best performance in any case. :)

Getting Started

Dependency & Initialization

Add dependency.

    compile 'moe.studio:logger:latest.release'

Initialization.

BLog.initialize(context);

Basic

Print log message.

BLog.v(TAG, "log verbose");
BLog.v("log verbose with default tag");

BLog.d(TAG, "log debug");
BLog.d("log debug with default tag");

BLog.i(TAG, "log info");
BLog.i("log info with default tag");

BLog.w(TAG, "log warning");
BLog.w("log warning with default tag");

BLog.e(TAG, "log error");
BLog.e("log error with default tag");

BLog.wtf(TAG, "log wtf");
BLog.wtf("log wtf with default tag");

Print event message.

BLog.event(TAG, "event A");
BLog.event("event B");
BLog.event("Excited!");

Get log files.

// Get log files;
File all = BLog.zippingLogFiles(LogSetting.LOG, null);
// Get log & event files.
File all = BLog.zippingLogFiles(LogSetting.LOG | LogSetting.EVENT, null);

// Get logs with addiction files.
List<File> attaches = new ArrayList<>();
attaches.add(outDate1);
attaches.add(outDate2);
File attach = BLog.zippingLogFiles(LogSetting.LOG | LogSetting.EVENT, attaches);

Advanced

Print exception.

Exception exception = new RuntimeException("...");

BLog.v(TAG, "runtime exception", exception);
BLog.v(exception);

Print String with format.

BLog.vfmt(TAG, "log %s with format string", "verbose");
BLog.dfmt(null, "log %s with format string", "debug");
BLog.ifmt(TAG, "log %s with format string", "info");
BLog.wfmt(null, "log %s with format string", "warning");
BLog.efmt(TAG, "log %s with format string", "error");
BLog.wtffmt(null, "log %s with format string", "wtf");

In general, BLog uses a worker thread to write log messages into file. If you want to log message synchronously into file, you'd better use the following api.

BLog.syncLog(LogPriority.VERBOSE, "TEST", "Sync Log.");
BLog.syncLog(LogPriority.DEBUG, "TEST", "Sync Log.");

Besides, you can set a custom LogAdapter to do some addiction jobs when executing a log.

LogSetting setting = new LogSetting.Builder(context)
                .setAdapter(new Log() {
                    @Override
                    public void log(int priority, String tag, String msg) {
                        // Do something.
                    }

                    @Override
                    public void onShutdown() {
                        // Do something.
                    }
                })
                .build();

BLog.initialize(setting);

Custom Setting

Initialize BLog

BLog.initialize(Context);

Initialize BLog with custom setting

LogSetting setting = new LogSetting.Builder(context)
        .setDefaultTag("TEST")
        .setLogDir(logDir.getPath())
        .setExpiredDay(1)
        .setLogcatLevel(LogLevel.DEBUG)
        .setLogfileLevel(LogLevel.INFO)
        .setEventLevel(LogLevel.VERBOSE)
        .setFormatter(new LogFormatterImpl())
        .setAdapter(new Log())
        .build();

BLog.initialize(setting);

In general, BLog will shutdown itself when the application is terminated, but you can use BLog#shutdown() to shutdown BLog.

For more usage showcases, please check out the test codes.

License

Licensed under the Apache License, Version 2.0 (the "License").