Android 中 log 的输出。
1.
Log.v(String tag, String msg); //VERBOSE
Log.d(String tag, String msg); //DEBUG
Log.i(String tag, String msg); //INFO
Log.w(String tag, String msg); //WARN
Log.e(String tag, String msg); //ERROR
以上log的级别依次升高,VERBOSE DEBUG信息应当只存在于开发中,INFO,WARN,ERROR这三种log将出现在发布版本中。
对于JAVA类中,可以声明一个字符串常量TAG,Logcat可以根据他来区分不同的log,例如在WindowsManagerService.java的类中,定义如下所示:
static final Sting TAG = "WindowManager"
需要打log的地方
Log.v(TAG, "Figuring out where to add app window" + client.asBinder() + "(token=" + token + ")");
2.
logcat使用方法如下所示:
logcat [options] [filterspecs]
option "-s" 用来设置过滤器,格式是这样的 <tag>[:priority]
其中 <tag> 表示log的component, tag (或者使用 * 表示所有) ,priority如下所示:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent
例
logcat -s *:s 不打任何log
logcat -s WindowMnager:V <-- 打印WindowManagerService 中 Verbose 信息
ps:如果在eclipse中查看Android log 输出,也就是logcat信息,可以 选择Windows > Show View > Other... > Android > LogCat。
本文介绍了Android中Log的五种输出级别及其应用场景,并提供了如何在代码中实现Log输出的具体示例。此外,还详细讲解了如何利用logcat工具进行日志过滤。
1659

被折叠的 条评论
为什么被折叠?



