Even if you have a debacher and can perform steps, you can't let go of the ease of debackloging. In the case of Android, you can use the standard Log class to achieve that goal, but many people would be happy if the Tag had the class name, method name, and line number in it!
When I thought about it, there was a person who realized it.
[
How to display "Class Name.Method Name: Line Number" in LogCat Tag on Android?
](http://kinsentansa.blogspot.jp/2012/06/androidlogcattag.html)
For some reason, I tried to classify this so that it can be used.
[code lang="java" light="true"] package jp.fuga.hoge.android.app;
import java.util.regex.Pattern; import jp.fuga.hoge.android.app.BuildConfig; import android.util.Log;
/** * log output class.
* Always use this class when outputting logs.
* At the time of release, the debacklog is not printed. * */ public class L {
/**
* Output a log for debugging. It is not output during production release.
*
* Message to output @param msg
*/
public static void d(String msg) {
if (! BuildConfig.DEBUG) return;
Log.d(getTag(), msg);
}
/**
* Output an error log. <br>
* Used to output logs during a catch or with unexpected behavior. <br>
* This log is assumed to be output to analyze errors that occur during the production release.
*
* Message to output @param msg
*/
public static void e(String msg) {
Log.e(getTag(), msg);
}
/**
* Ibid.
*
* @param msg
* @param t
*/
public static void e(String msg, Throwable t) {
Log.e(getTag(), msg, t);
}
/**
* Generate tags
*
* @return className#methodName:line
*/
private static String getTag() {
final StackTraceElement trace = Thread.currentThread().getStackTrace()[4];
final String cla = trace.getClassName();
Pattern pattern = Pattern.compile("[\\.] +");
final String[] splitedStr = pattern.split(cla);
final String simpleClass = splitedStr[splitedStr.length - 1];
final String mthd = trace.getMethodName();
final int line = trace.getLineNumber();
final String tag = simpleClass + "#" + mthd + ":" + line;
return tag;
}
}
[/code]
The point is that BuildConfig controls that the debacklog is not output when the release build is made.
Here's how to use it
[code lang="java" light="true"] L.d("Debacklog"); [/code]
Have a good debug life.