代码
package com.che.carcheck.support.util;
import android.util.Log;
/**
* Created by yutianran on 16/2/25.
*/
public class LogUtil {
private static final String TAG = "print";
public static void print(String msg) {
if (false) {
return;
}
String tmp = getLineFile() + getLineMethod() + msg;
Log.i(TAG, tmp);
}
public static void print(String tag,String msg) {
if (false) {
return;
}
String tmp = getLineFile() + getLineMethod() + msg;
Log.i(tag, tmp);
}
public static String getLineMethod() {
StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
StringBuffer toStringBuffer = new StringBuffer("[")
.append(traceElement.getLineNumber()).append(" | ")
.append(traceElement.getMethodName()).append("]");
return toStringBuffer.toString();
}
public static String getLineFile() {
StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
return traceElement.getFileName();
}
}
效果