package cn.yyxx.commsdk.core.utils;

import android.app.Application;

import com.dolin.zap.Zap;
import com.dolin.zap.entity.Config;
import com.dolin.zap.entity.Level;

import cn.yyxx.support.hawkeye.LogUtils;

public final class YYLog {

    private static final String TAG = "YYLog";
    private static boolean hasZapInit = false;

    private YYLog() {
    }

    public static void initZap(Application application) {
        Level level = null;
        if (LogUtils.DEBUG) {
            level = Level.DEBUG;
        } else {
            level = Level.INFO;
        }
        Config config = new Config.Builder()
                //logcat输出最低等级
                .setLogcatLevel(level)
                //是否开启缓存日志
                .setRecordEnable(true)
                //缓存日志最低等级
                .setRecordLevel(Level.DEBUG)
                //是否开启压缩缓存日志内容
                .setCompressEnable(true)
                //缓存文件的过期时间
                .setOverdueDay(3)
                //缓存文件大小限制，超过则会自动扩容新文件
                .setFileSizeLimitDay(10)
                .create();
        Zap.initialize(application, config);
        hasZapInit = true;
    }

    public static void d(Object object) {
        d(TAG, object);
    }

    public static void d(String tag, Object object) {
        if (hasZapInit) {
            Zap.d(tag, object);
        } else {
            LogUtils.d(tag, object);
        }
    }

    public static void i(Object object) {
        i(TAG, object);
    }

    public static void i(String tag, Object object) {
        if (hasZapInit) {
            Zap.i(tag, object);
        } else {
            LogUtils.i(tag, object);
        }
    }

    public static void e(Object object) {
        e(TAG, object);
    }

    public static void e(String tag, Object object) {
        if (hasZapInit) {
            Zap.e(tag, object);
        } else {
            LogUtils.e(tag, object);
        }
    }

    public static void logHandler(String msg) {
        LogUtils.logHandler(msg);
    }

}
