内核开发的log
printk提供了8种日志级别():
[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
#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.");
cat /proc/kmsg
要在c/c++中使用Log,很简单。通常的做法是:
定义自己的TAG_LOG宏;包含头文件log.h;然后在需要记录Log的地方直接用LOGV/LOGD/LOGI/LOGW/LOGE等即可。
比如,文件lights.c中就在开头这样写,
#define LOG_TAG "lights"
#include
需要在.mk文件新增如下
common_shared_libraries :=libutils liblog
LOCAL_SHARED_LIBRARIES := $(common_shared_libraries)
然后在该文件的后续部分,直接用ALOGV/ALOGE等来输出日志就可以。
java code log
import android.util.Log;
private static final String LOG_TAG = "MY_LOG_TAG";
Log.i(LOG_TAG, "This is the log printed by Log.i in android user space.");
阅读(1699) | 评论(0) | 转发(0) |