Last active
June 10, 2016 16:42
-
-
Save frontrangerider2004/e9e0ffd5d733cef51083ea21d7dc844b to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
/** | |
* Android Logger Util: | |
* Handles making nice pretty debug statements. | |
*/ | |
public class Logger { | |
private final String TAG; | |
private final Boolean DEBUG = true; //TODO get this from BuildConfig | |
private final Boolean WARN = true; //TODO get this from BuildConfig | |
private final Boolean ERROR = true; //TODO get this from BuildConfig | |
private static final String SPACE = " "; | |
private static final String NEW_LINE = "\n"; | |
private static final String EMPTY_CHAR = ""; | |
private static final String RIGHT_BRACE = "]"; | |
private static final String LEFT_BRACE = "["; | |
public Logger(String tag){ | |
Log.d(tag, "Creating Logger for: " + tag); | |
this.TAG = tag; | |
} | |
public String getTAG(){ | |
return this.TAG; | |
} | |
public Boolean getDEBUG(){ | |
return this.DEBUG; | |
} | |
public Boolean getERROR() { | |
return ERROR; | |
} | |
public Boolean getWARN() { | |
return WARN; | |
} | |
/** | |
* Debug: | |
* Calls Android Log.d with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
* @param data | |
*/ | |
public void d(String methodName, String msg, Object data){ | |
if(this.getDEBUG()) Log.d( | |
this.getTAG(), | |
LEFT_BRACE + | |
methodName + | |
RIGHT_BRACE + | |
SPACE + | |
msg + | |
SPACE + | |
data.toString() | |
); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.d with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
*/ | |
public void d(String methodName, String msg){ | |
this.d(methodName, msg, NEW_LINE); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.d with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param data | |
*/ | |
public void d(String methodName, Object data){ | |
this.d(methodName, EMPTY_CHAR, data); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.d with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
*/ | |
public void d(String methodName){ | |
this.d(methodName, EMPTY_CHAR, NEW_LINE); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.e with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
* @param data | |
*/ | |
public void e(String methodName, String msg, Object data){ | |
if(this.getERROR()) Log.e( | |
this.getTAG(), | |
LEFT_BRACE + | |
methodName + | |
RIGHT_BRACE + | |
SPACE + | |
msg + | |
SPACE + | |
data.toString() | |
); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.e with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
*/ | |
public void e(String methodName, String msg){ | |
this.e(methodName, msg, NEW_LINE); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.e with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param data | |
*/ | |
public void e(String methodName, Object data){ | |
this.e(methodName, EMPTY_CHAR, data); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.e with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
*/ | |
public void e(String methodName){ | |
this.e(methodName, EMPTY_CHAR, NEW_LINE); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.w with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
* @param data | |
*/ | |
public void w(String methodName, String msg, Object data){ | |
if(this.getWARN()) Log.w( | |
this.getTAG(), | |
LEFT_BRACE + | |
methodName + | |
RIGHT_BRACE + | |
SPACE + | |
msg + | |
SPACE + | |
data.toString() | |
); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.w with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param msg | |
*/ | |
public void w(String methodName, String msg){ | |
this.w(methodName, msg, NEW_LINE); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.w with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
* @param data | |
*/ | |
public void w(String methodName, Object data){ | |
this.w(methodName, EMPTY_CHAR, data); | |
} | |
/** | |
* Debug: | |
* Calls Android Log.w with the supplied params. | |
* | |
* Output Format Note: | |
* The methodName param will be wrapped in square brackets. | |
* @param methodName | |
*/ | |
public void w(String methodName){ | |
this.w(methodName, EMPTY_CHAR, NEW_LINE); | |
} | |
}//End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment