package com.ym.library.utils;


import android.util.Log;


public class LogHelper {
    public static final String TAG = "ZX-Logger";
    private static boolean mLogEnabled = true;

    public static boolean isLogEnabled() {
        return mLogEnabled;
    }

    public static void i(String tag, String message) {
        if (mLogEnabled) {
            Log.i(tag + "-->:" + getTargetStackTraceElement(), message);
        }
    }

    public static void e(String tag, String message) {
        if (mLogEnabled) {
            Log.e(tag + "-->" + getTargetStackTraceElement(), message);
        }
    }

    public static void e(String tag, String message, Throwable tr) {
        if (mLogEnabled) {
            Log.e(tag + "-->" + getTargetStackTraceElement(), message, tr);
        }
    }

    public static void w(String tag, String message) {
        if (mLogEnabled) {
            Log.w(tag + "-->:" + getTargetStackTraceElement(), message);
        }
    }

    public static void v(String tag, String message) {
        if (mLogEnabled) {
            Log.v(tag + "-->:" + getTargetStackTraceElement(), message);
        }
    }

    public static void d(String tag, String message) {
        if (mLogEnabled) {
            Log.d(tag + "-->:" + getTargetStackTraceElement(), message);
        }
    }

    private static String getTargetStackTraceElement() {
        StackTraceElement targetStackTrace = null;
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        if (stackTrace.length >= 4) {
            targetStackTrace = stackTrace[4];
        }
        String s = "";
        if (null != targetStackTrace) {
            s = "(" + targetStackTrace.getFileName() + ":" + targetStackTrace.getLineNumber() + ")";
        }
        return s;
    }
}