xcy396
2/28/2018 - 9:14 AM

XLog

微信 Mars 库 XLog 模块

// implementation 'com.tencent.mars:mars-xlog:1.0.6'

import android.content.Context;
import android.os.Environment;
import com.tencent.mars.xlog.Log;
import com.tencent.mars.xlog.Xlog;

/**
 * Created by Mark Xu on 2017/11/22.
 * Site: http://xuchongyang.com
 */

public class XLog {

    public static void init(Context context, String namePrefix) {
        System.loadLibrary("stlport_shared");
        System.loadLibrary("marsxlog");
        final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();
        final String logPath = sdcard + "/" + namePrefix + "/log";

        final String cachePath = context.getFilesDir() + "/xlog";

        if (BuildConfig.DEBUG) {
            Xlog.appenderOpen(Xlog.LEVEL_DEBUG, Xlog.AppednerModeAsync, cachePath, logPath,
                    namePrefix, "");
            Xlog.setConsoleLogOpen(true);
        } else {
            Xlog.appenderOpen(Xlog.LEVEL_INFO, Xlog.AppednerModeAsync, cachePath, logPath,
                    namePrefix, "");
        }
        Log.setLogImp(new Xlog());
    }

    public static void i(String tag, String msg) {
        Log.i(tag, msg);
    }

    public static void i(String tag, String msg, Object... obj) {
        Log.i(tag, msg, obj);
    }

    public static void d(String tag, String msg) {
        Log.i(tag, msg);
    }

    public static void d(String tag, String msg, Object... obj) {
        Log.i(tag, msg, obj);
    }

    public static void w(String tag, String msg) {
        Log.i(tag, msg);
    }

    public static void w(String tag, String msg, Object... obj) {
        Log.i(tag, msg, obj);
    }

    public static void e(String tag, String msg) {
        Log.i(tag, msg);
    }

    public static void e(String tag, String msg, Object... obj) {
        Log.i(tag, msg, obj);
    }
}