Android调试驱动抓log的方法

转自:http://blog.csdn.net/menghnhhuan/article/details/7470583

在程序开发过程中,LOG是广泛使用的用来记录程序执行过程的机制,它既可以用于程序调试,也可以用于产品运营中的事件记录。在Android系统中,提供了简单、便利的LOG机制,开发人员可以方便地使用。在这一篇文章中,我们简单介绍在Android驱动LOG的使用和查看方法。

        Android内核是基于Linux Kerne 2.36的,因此,Linux KernelLOG机制同样适合于Android内核,它就是有名的printk,与C语言的printf齐名。与printf类似,printk提供格式化输入功能,同时,它也具有所有LOG机制的特点--提供日志级别过虑功能。printk提供了8种日志级别(<linux/kernel.h>):

#define KERN_EMERG  "<0>"     /* system is unusable           */  

#define KERN_ALERT  "<1>"     /* action must be taken immediately */  

#define KERN_CRIT   "<2>"     /* critical conditions          */  

#deinfe KERN_ERR    "<3>"     /* error conditions         */  

#deinfe KERN_WARNING    "<4>"     /* warning conditions           */  

#deinfe KERN_NOTICE "<5>"     /* normal but significant condition */  

#deinfe KERN_INFO   "<6>"     /* informational            */  

#deinfe KERN_DEBUG  "<7>"     /* debug-level messages         */  

printk的使用方法:

printk(KERN_ALERT"This is the log printed by printk in linux kernel space.");

KERN_ALERT表示日志级别,后面紧跟着要格式化字符串。

Android系统中,printk输出的日志信息保存在/proc/kmsg中,使用查看命令:

adb shell cat /proc/kmsg  | grep "alarm" //grep "alarm"表示只抓取alarm的信息

或者:

USER-NAME@MACHINE-NAME:~/Android$ adb shell

root@android:/ # cat  /proc/kmsg | grep "alarm" //grep "alarm"表示只抓取alarm的信息



你可能感兴趣的:(Android调试驱动抓log的方法)