package epson.print.Util;

import android.util.Log;

import epson.print.CommonDefine;

public final class EPLog {
    public static final String TAG = "Epson App";
    private static boolean isDebug = false;

    public static final void heap(String str) {
    }

    private static String null2str(String str) {
        return str == null ? "(null)" : str;
    }

    private EPLog() {
    }

    public static void setDebuggable(boolean z) {
        if (z) {
            isDebug = true;
        } else {
            isDebug = false;
        }
    }

    public static void v() {
        if (isDebug) {
            Log.v("Epson App", getMetaInfo());
        }
    }

    public static void v(String str) {
        if (isDebug) {
            Log.v("Epson App", getMetaInfo() + null2str(str));
        }
    }

    public static void v(String str, String str2) {
        if (isDebug) {
            Log.v(str, getMetaInfo() + null2str(str2));
        }
    }

    public static void d() {
        if (isDebug) {
            Log.d("Epson App", getMetaInfo());
        }
    }

    public static void d(String str) {
        if (isDebug) {
            Log.d("Epson App", getMetaInfo() + null2str(str));
        }
    }

    public static void d(String str, String str2) {
        if (isDebug) {
            Log.d(str, getMetaInfo() + null2str(str2));
        }
    }

    public static void i() {
        if (isDebug) {
            Log.i("Epson App", getMetaInfo());
        }
    }

    public static void i(String str) {
        if (isDebug) {
            Log.i("Epson App", getMetaInfo() + null2str(str));
        }
    }

    public static void i(String str, String str2) {
        if (isDebug) {
            Log.i(str, getMetaInfo() + null2str(str2));
        }
    }


    public static void w(String str) {
        if (isDebug) {
            Log.w("Epson App", getMetaInfo() + null2str(str));
        }
    }

    public static void w(String str, String str2) {
        if (isDebug) {
            Log.w(str, getMetaInfo() + null2str(str2));
        }
    }

    public static void w(String str, Throwable th) {
        if (isDebug) {
            Log.w("Epson App", getMetaInfo() + null2str(str), th);
            printThrowable(th);
            if (th.getCause() != null) {
                printThrowable(th.getCause());
            }
        }
    }

    public static void w(String str, String str2, Throwable th) {
        if (isDebug) {
            Log.w(str, getMetaInfo() + null2str(str2), th);
            printThrowable(str, th);
            if (th.getCause() != null) {
                printThrowable(th.getCause());
            }
        }
    }

    public static void e(String str) {
        if (isDebug) {
            Log.e("Epson App", getMetaInfo() + null2str(str));
        }
    }

    public static void e(String str, String str2) {
        if (isDebug) {
            Log.e(str, getMetaInfo() + null2str(str2));
        }
    }

    public static void e(String str, Throwable th) {
        if (isDebug) {
            Log.e("Epson App", getMetaInfo() + null2str(str), th);
            printThrowable(th);
            if (th.getCause() != null) {
                printThrowable(th.getCause());
            }
        }
    }

    public static void e(String str, String str2, Throwable th) {
        if (isDebug) {
            Log.e(str, getMetaInfo() + null2str(str2), th);
            printThrowable(str, th);
            if (th.getCause() != null) {
                printThrowable(th.getCause());
            }
        }
    }

    public static void e(Throwable th) {
        if (isDebug) {
            printThrowable(th);
            if (th.getCause() != null) {
                printThrowable(th.getCause());
            }
        }
    }

    private static void printThrowable(Throwable th) {
        Log.e("Epson App", th.getClass().getName() + ": " + th.getMessage());
        for (StackTraceElement stackTraceElement : th.getStackTrace()) {
            Log.e("Epson App", "  at " + getMetaInfo(stackTraceElement));
        }
    }

    private static void printThrowable(String str, Throwable th) {
        Log.e(str, th.getClass().getName() + ": " + th.getMessage());
        for (StackTraceElement stackTraceElement : th.getStackTrace()) {
            Log.e("Epson App", "  at " + getMetaInfo(stackTraceElement));
        }
    }

    private static String getMetaInfo() {
        return getMetaInfo(Thread.currentThread().getStackTrace()[4]);
    }

    public static String getMetaInfo(StackTraceElement stackTraceElement) {
        StringBuffer stringBuffer = new StringBuffer();
        String className = stackTraceElement.getClassName();
        String substring = className.substring(className.lastIndexOf(CommonDefine.DOT) + 1);
        String methodName = stackTraceElement.getMethodName();
        int lineNumber = stackTraceElement.getLineNumber();
        stringBuffer.append("[");
        stringBuffer.append(substring);
        stringBuffer.append("#");
        stringBuffer.append(methodName);
        stringBuffer.append(":");
        stringBuffer.append(lineNumber);
        stringBuffer.append("]");
        return new String(stringBuffer);
    }

    public static final void heap() {
        heap("Epson App");
    }
}
