Last active
December 19, 2015 09:19
-
-
Save Gopinathp/5932580 to your computer and use it in GitHub Desktop.
GreenLogger - Smart Logger for Android. 1. Turns off debug/verbose logs on production builds of the app.
2. Logs for the entire app using a single TAG "GreenLogger" which you can modify if you wish to.
3. Helps in easy log filtering on production devices. Filter by "GreenLogger" on adb logcat. (Usage: adb logcat | grep GreenLo)
4. Convenient met…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gopinath.android.util; | |
import android.content.SharedPreferences; | |
import android.util.Log; | |
import com.google.gson.Gson; | |
/** | |
* GreenLogger class Features: <br> | |
* 1. Logging is made easy and manageable <br> | |
* 2. Turns off debug/verbose logs on production builds.<br> | |
* 3. Easy log filtering on production devices. <br>Filter by "GreenLogger" on adb logcat. <br> (Usage: adb logcat | grep GreenLo | |
* | |
* @author gopinath | |
* | |
*/ | |
public class L { | |
public enum LOG_LEVEL { | |
VERBOSE, DEBUG, INFO, WARN, ERROR | |
} | |
public static final LOG_LEVEL logLEVEL = (BuildConfig.DEBUG) ? LOG_LEVEL.VERBOSE: LOG_LEVEL.ERROR; | |
private static final String TAG = "GreenLogger"; | |
public static void v(String message) { | |
if(L.logLEVEL.ordinal() <= LOG_LEVEL.VERBOSE.ordinal()) { | |
Log.v(TAG, message); | |
} | |
} | |
public static void d(String message) { | |
if(L.logLEVEL.ordinal() <= LOG_LEVEL.DEBUG.ordinal()) { | |
Log.d(TAG, message); | |
} | |
} | |
public static void i(String message) { | |
if(L.logLEVEL.ordinal() <= LOG_LEVEL.INFO.ordinal()) { | |
Log.i(TAG, message); | |
} | |
} | |
public static void w(String message) { | |
if(L.logLEVEL.ordinal() <= LOG_LEVEL.WARN.ordinal()) { | |
Log.w(TAG, message); | |
} | |
} | |
public static void e(String message) { | |
if(L.logLEVEL.ordinal() <= LOG_LEVEL.ERROR.ordinal()) { | |
Log.e(TAG, message); | |
} | |
} | |
public static void constructEvent(String category, String action, | |
String label, String value) { | |
Log.v(TAG + "ana" + category, action + " label: " + label + " , value = " + value); | |
} | |
public static void print(SharedPreferences mPrefs) { | |
v(new Gson().toJson(mPrefs.getAll())); | |
} | |
public static void v(String tag, String notifMsg) { | |
v(tag + notifMsg); | |
} | |
public static void print(String string, SharedPreferences sharedPreferences) { | |
L.d(string); | |
L.print(sharedPreferences); | |
} | |
public static void print(Exception e) { | |
if (e != null) { | |
L.d("Exception: " + Log.getStackTraceString(e)); | |
} | |
else | |
L.d("exception which is null"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment