日志工具Log(android.util.Log),共有五个方法打印日志
package android.util;
public final class Log {
public static final int ASSERT = 7;
public static final int DEBUG = 3;
public static final int ERROR = 6;
public static final int INFO = 4;
public static final int VERBOSE = 2;
public static final int WARN = 5;
Log() {
throw new RuntimeException("Stub!");
}
public static int v(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int v(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int d(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int d(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int i(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int i(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int w(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int w(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static native boolean isLoggable(String var0, int var1);
public static int w(String tag, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int e(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int e(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int wtf(String tag, String msg) {
throw new RuntimeException("Stub!");
}
public static int wtf(String tag, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int wtf(String tag, String msg, Throwable tr) {
throw new RuntimeException("Stub!");
}
public static String getStackTraceString(Throwable tr) {
throw new RuntimeException("Stub!");
}
public static int println(int priority, String tag, String msg) {
throw new RuntimeException("Stub!");
}
}
级别从低到高:
- Log.v() 最为琐碎的,意义最小的日志信息,对应级别verbose
- Log.d() 打印调试信息,最常用,对应级别debug
- Log.i() 打印比较重要的数据,可以帮助分析用户行为数据,对应级别info
- Log.w() 打印警告信息,此处有潜在危险,需要修复,对应级别warn
- Log.e() 打印程序中的错误信息,,必须修复,对应级别error
注1:tag 参数一般为当前的类名,msg想打印的具体信息
private String tag = MainActivity.class.getSimpleName();
/**
* Activity 被创建时
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(tag, "onCreate");
}
注2:System.out.println(),虽然在eclipse中输入syso,按下代码提示键就会出来,但在Android studio中不支持这种快捷方式。打印日志的的优点:可以添加过滤器、有等级区分、打印可控制、有打印时等。
注3:快捷输入,如输入logd,然后点击tab键,就会补全。
在onCreate()外面输入logt,点击tab,就会以当前的类名作为值生成一个TAG常量
private static final String TAG = "MainActivity";
注4:添加过滤器,选择显示级别,搜索等等
图片.png