客户端dmesg_嵌入式 Linux进程间通信(四)——Linux系统日志

本文介绍了Linux系统日志的组成部分,包括syslogd和klogd,以及常见的日志文件。讲解了syslog函数的使用,配置文件/etc/syslog.conf的设置,如何搭建Linux日志服务器,以及客户端日志配置。最后提到了日志管理工具logrotate的作用和配置参数。
摘要由CSDN通过智能技术生成

嵌入式 Linux进程间通信(四)——Linux系统日志

syslog 是一种工业标准的协议,用来记录设备的日志。Linux日志系统由系统日志监控程序syslogd和内核日志监控程序klogd组成,两个监控程序都是守护程序(daemon),且都注册成了系统服务。syslogd专门记录非内核的其他设备所产生的日志,当系统的控制权由系统交给init的时候,日志信息的记录由syslogd负责记录。Klogd主要负责内核所产生的日志。内核日志记录信息由dmesg /var/log/dmesg查看。

常见linux系统的日志文件:

/var/log/dmesg      内核引导信息日志

/var/log/message    标准系统错误信息日志

/var/log/maillog    邮件系统信息日志

/var/log/cron       计划任务日志

/var/log/secure     安全信息日志

完整的syslog日志中包含产生日志的程序模块(Facility)、严重性(Severity或Level)、时间、主机名或IP、进程名、进程ID和正文。

系统日志信息的格式:timestamp hostname ident[pid]:log message

一、syslog函数

Linux系统提供了一组系统日志的接口函数,如下:

#include

void openlog(const char *ident, int option, int facility);

void syslog(int priority, const char *format, ...);

void closelog(void);

调用openlog、closelog是可选择的。如果不调用openlog,则在第一次调用syslog时,自动调用openlog。

参数解读如下:

ident:

指向信息的指针,一般为程序名,ident所表示的字符串将固定地加在每行日志的前面以标识这个日志,通常就写成当前程序的名称以作标记

option:

LOG_CONS       Write directly to system console if there is an error while sending to system  logger.

LOG_NDELAY     Open  the  connection  immediately  (normally, the connection is opened when the first message is logged).

LOG_NOWAIT     Don’t wait for child processes that may have been created while logging  the  message.(The  GNU  C  library does not create a child process, so this option has no effect on Linux.)

LOG_ODELAY     The converse of LOG_NDELAY; opening of the connection is  delayed  until  syslog()  is called.  (This is the

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值