package com.onebit.logger;

import android.os.Build;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by scijoker on 08.10.15.
 */
public class Logger {

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

    public static void d(String logMsg) {
        d(getCurrentClassName(), getCurrentMethodName() + "(): " + logMsg);
    }

    public static void dd(String tag, Object source) {
        if (containsJsonStr(source)) {
            try {
                format(tag, new JSONObject(source.toString()).toString(2));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            format(tag, source);
        }
    }

    private static String getSplitter(int length) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            builder.append("-");
        }
        return builder.toString();
    }

    private static void format(String tag, Object source) {
        tag = " " + tag + " ";
        d(" ", " ");
        d(" ", getSplitter(50) + tag + getSplitter(50));
        d(" ", "" + source);
        d(" ", getSplitter(100 + tag.length()));
        d(" ", " ");
    }

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

    private static String getCurrentClassName() {
        String className = Thread.currentThread().getStackTrace()[4].getClassName();

        String[] temp = className.split("[\\.]");
        className = temp[temp.length - 1];
        return className;
    }

    private static boolean containsJsonStr(Object test) {
        try {
            new JSONObject(test.toString());
        } catch (JSONException ex) {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    new JSONArray(test);
                }
            } catch (JSONException ex1) {
                return false;
            }
        }
        return true;
    }
}

@@ -16,14 +16,23 @@
 bit.
-logger
+noteslite.utils
 ;%0A%0Ai
@@ -233,16 +233,57 @@
 Logger %7B
+%0A    private static boolean DEBUG = true;
 %0A%0A    pu
@@ -323,24 +323,59 @@
 ring arg) %7B%0A
+        if (isDebugEnable()) %7B%0A    
         Log.
@@ -383,24 +383,34 @@
 (tag, arg);%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -442,24 +442,59 @@
 g logMsg) %7B%0A
+        if (isDebugEnable()) %7B%0A    
         d(ge
@@ -553,24 +553,34 @@
  + logMsg);%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -612,32 +612,367 @@
 ng tag, 
+JSON
 Object 
+j
 so
-urce) %7B
+nObject) %7B%0A        if (isDebugEnable()) %7B%0A            try %7B%0A                format(tag, jsonObject.toString(2));%0A            %7D catch (JSONException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void dd(String tag, Object source) %7B%0A        if (!isDebugEnable()) %7B%0A            return;%0A        %7D
 %0A       
@@ -1033,30 +1033,26 @@
             
-format
+dd
 (tag, new JS
@@ -2581,11 +2581,170 @@
 e;%0A    %7D
+%0A%0A    private static boolean isDebugEnable() %7B%0A        return DEBUG;%0A    %7D%0A%0A    public static void setEnable(boolean flag) %7B%0A        Logger.DEBUG = flag;%0A    %7D
 %0A%7D%0A

Update Logger.java