博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
syslog
阅读量:5019 次
发布时间:2019-06-12

本文共 2327 字,大约阅读时间需要 7 分钟。

syslog

1. 声明

#include 
void openlog(char*ident,int option ,int facility);void syslog(int priority,char*format,……)void closelog()

2. openlog

例子:

openlog(argv[0], LOG_PID, LOG_LOCAL5);

a. openlog会指定一个indent,那么这个程序的每个信息前面都有这个indent,一般是这个程序名。

b. option控制syslog行为:

option       The option argument to openlog() is an OR of any of these:       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 default, and  need  not  be                      specified.)       LOG_PERROR     (Not in POSIX.1-2001 or POSIX.1-2008.)  Print to stderr as well.       LOG_PID        Include PID with each message.

c. The facility argument is used to specify what type of program is logging the message. This lets the configuration file specify that messages from

different facilities will be handled differently.
配置文件是/etc/syslog.conf,可以配置不同程序类型,保存不同的位置:

kern.*                  /var/log/kern.loguser.*                  /var/log/sysloglocal2.*                /var/log/network.loglocal3.*                /var/log/onvif.loglocal5.*                /var/log/media.loglocal6.*                /var/log/rtspd.log

syslog

例子:

syslog(LOG_DEBUG, "This is test message %s\n", argv[0]);

第一个参数是level,表示消息的重要性,syslog man page里关于level的选项,从上往下重要性逐渐下降。

level       This determines the importance of the message.  The levels are, in order of decreasing importance:       LOG_EMERG      system is unusable       LOG_ALERT      action must be taken immediately       LOG_CRIT       critical conditions       LOG_ERR        error conditions       LOG_WARNING    warning conditions       LOG_NOTICE     normal, but significant, condition       LOG_INFO       informational message       LOG_DEBUG      debug-level message

后面的参数就是fmt与参数。

closelog

closelog()关闭描述符。是否使用是可选的。

转载于:https://www.cnblogs.com/gr-nick/p/11125762.html

你可能感兴趣的文章
pta 编程题14 Huffman Codes
查看>>
初始化bootstrap treeview树节点
查看>>
python selenium向<sapn>标签中写入内容
查看>>
JS常用坐标
查看>>
使用”结构化的思考方式“来编码和使用”流程化的思考方式“来编码,孰优孰劣?...
查看>>
C#调用斑马打印机打印条码标签(支持COM、LPT、USB、TCP连接方式和ZPL、EPL、CPCL指令)【转】...
查看>>
关于git的认证方式
查看>>
字符串按照字典序排列
查看>>
IOS 开发调用打电话,发短信
查看>>
CI 框架中的日志处理 以及 404异常处理
查看>>
keepalived介绍
查看>>
css3 标签 background-size
查看>>
python itertools
查看>>
Linux内核调试技术——jprobe使用与实现
查看>>
样式、格式布局
查看>>
ubuntu设计文件权限
查看>>
Vue双向绑定原理详解
查看>>
Android基础总结(5)——数据存储,持久化技术
查看>>
关于DataSet事务处理以及SqlDataAdapter四种用法
查看>>
bootstrap
查看>>