Last active
August 29, 2015 14:02
-
-
Save JMPergar/7428e7a1fc26931ca7c3 to your computer and use it in GitHub Desktop.
LogManager.java
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
import android.util.Log; | |
public final class LogManager { | |
public static final int VERBOSE = 0; | |
public static final int DEBUG = 1; | |
public static final int INFO = 2; | |
public static final int WARN = 3; | |
public static final int ERROR = 4; | |
public static final int WTF = 5; | |
public static void log(int level, String className, String methodName, String msg) { | |
if (isLoggable(level)) { | |
String tag = generateTag(className, methodName); | |
switch (level) { | |
case VERBOSE: Log.v(tag, msg); break; | |
case DEBUG: Log.d(tag, msg); break; | |
case INFO: Log.i(tag, msg); break; | |
case WARN: Log.w(tag, msg); break; | |
case ERROR: Log.e(tag, msg); break; | |
case WTF: Log.w(tag, msg); break; | |
} | |
} | |
} | |
public static void log(int level, String className, String methodName, String msg, Throwable tr) { | |
if (isLoggable(level)) { | |
String tag = generateTag(className, methodName); | |
switch (level) { | |
case VERBOSE: Log.v(tag, msg, tr); break; | |
case DEBUG: Log.d(tag, msg, tr); break; | |
case INFO: Log.i(tag, msg, tr); break; | |
case WARN: Log.w(tag, msg, tr); break; | |
case ERROR: Log.e(tag, msg, tr); break; | |
case WTF: Log.w(tag, msg, tr); break; | |
} | |
} | |
} | |
private static boolean isLoggable (int level) { | |
return (BaseApplication.isDebuggable() || level > DEBUG); | |
} | |
private static String generateTag(String className, String methodName) { | |
return String.format("%s/%s", className, methodName); | |
} | |
} |
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
public class BaseApplication extends Application { | |
private static Context context; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
context = getApplicationContext(); | |
} | |
public static Context getContext() { | |
return context; | |
} | |
public static boolean isDebuggable() { | |
boolean isDebuggable = (0 != (getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)); | |
return isDebuggable; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment