Linux中的log介绍(三)---内核日志

内核日志的存储

 1.    地址

内核的日志存在log_buf指向的内存缓冲区中。

大小在新的内核是可配置的,CONFIG_LOG_BUF_SHIFT=xx

 2.  格式

 <level>xxxxxx


API

(1) printk:内核代码中常见的日志输出方式

(2)do_syslog/syslog: 内核提供的系统调用,用来操作log_buf

(3)klogctl:C库中提供的函数,用来使用上面的系统调用。

syslog系统调用支持下面的命令:

       *      0 -- Close the log.  Currently a NOP.

       *      1 -- Open the log.Currently a NOP.

       *      2 -- Read from the log.

        *     3 -- Read all messages remaining in the ring buffer.

       *      4 -- Read and clear allmessages remaining in the ring buffer

       *      5 -- Clear ring buffer.

       *      6 -- Disable printk toconsole

       *      7 -- Enable printk toconsole

       *      8 -- Set level of messagesprinted to console

       *      9 -- Return number ofunread characters in the log buffer

       *     10 -- Return size of the logbuffer

 

Tool

在shell中可以使用下面的方法直接操作内核log日志

(1)  dmesg:用来查看log_buf中的数据;

(2)  cat /proc/kmsg :也可用来读取log_buf中的数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值