package de.frajul.endlessroll.main;

import android.util.Log;

/**
 * Created by Julian on 23.11.2015.
 */
public class GameLog {

    private final static String TAG = "GameLog";
    public static boolean debugging = true;

    public static void i(String message) {
        Log.i(TAG + getCallerInfo(), message);
    }

    public static void d(String message) {
        if (debugging)
            Log.d(TAG + getCallerInfo(), message);
    }

    public static void e(String message) {
        Log.e(TAG + getCallerInfo(), message);
    }

    public static void e(Throwable error) {
        Log.e(TAG + getCallerInfo(), error.getMessage(), error);
    }

    //Possible to get Method which called i, d, e
    //Method found at stack[4]
    public static void stack() {
        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
        Log.i(TAG + "Stack", "StackSize: " + stack.length);
        for (int i = 0; i < stack.length; i++) {
            Log.i(TAG + "Stack", i + ": " + stack[i]);
        }
    }

    private static String getCallerInfo() {
        StackTraceElement[] stack = Thread.currentThread().getStackTrace();
        return "(" + stack[4].getFileName() + ", " + stack[4].getMethodName() + ", " + stack[4].getLineNumber() + ")";
    }
}
