How adb prints the kernel output log

https://www.jianshu.com/p/9b657c3c3560

https://www.jianshu.com/p/9b657c3c3560

How adb prints the kernel output log

2016.06.13 20:23* Word Count 198 Read 2665 Comments 1

Log output of the Android kernel

The Android kernel is based on the Linxu kernel, so its log mechanism is also universal. The printk function is used in the Android kernel for Log output. Similar to printf in C language, printk provides formatted input function, and at the same time, it also has all the characteristics of LOG mechanism - providing log level filtering function. printk provides 8 log levels (detailed definitions are in include/linux/kern_levels.h):

#ifndef __KERN_LEVELS_H__
#define __KERN_LEVELS_H__

#define KERN_SOH        "\001"          /* ASCII Start Of Header */
#define KERN_SOH_ASCII  '\001'

#define KERN_EMERG      KERN_SOH "0"    /* system is unusable */
#define KERN_ALERT      KERN_SOH "1"    /* action must be taken immediately */
#define KERN_CRIT       KERN_SOH "2"    /* critical conditions */
#define KERN_ERR        KERN_SOH "3"    /* error conditions */
#define KERN_WARNING    KERN_SOH "4"    /* warning conditions */
#define KERN_NOTICE     KERN_SOH "5"    /* normal but significant condition */
#define KERN_INFO       KERN_SOH "6"    /* informational */
#define KERN_DEBUG      KERN_SOH "7"    /* debug-level messages */

#define KERN_DEFAULT    KERN_SOH "d"    /* the default kernel loglevel */

/*
 * Annotation for a "continued" line of log printout (only done after a
 * line that had no enclosing \n). Only to be used by core/arch code
 * during early bootup (a continued line is not SMP-safe otherwise).
 */
#define KERN_CONT       ""

#endif

The easiest way to use printk:

//KERN_ALERT表示日志级别,后面紧跟着要格式化字符串。
printk(KERN_ALERT "This is the log printed by printk in linux kernel space.");

How to use printk's formatted output:

printk(KERN_ERR "%s: Invalid parameter\n", __func__);

Output kernel print information in the case of adb connect

In the Android system, the log information output by printk is stored in /proc/kmsg. To view the content of /proc/kmsg, just enter the following command on the command line

shell@rk3288_box:/ # cat  /proc/kmsg

The output result is as shown in the figure

Paste_Image.png

Take a walk with a small gift, come to Jianshu and follow me





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325513665&siteId=291194637