array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 111string(0) "" int(1) int(10) int(70) int(8640000) string(13) "likecs_art_db" array(1) { ["query"]=> array(1) { ["match_all"]=> object(stdClass)#28 (0) { } } } array(1) { ["createtime.keyword"]=> array(1) { ["order"]=> string(4) "desc" } } int(10) int(0) int(8640000) array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 在C语言中使用syslog打印日志到日志文件 - 爱码网

参见 《unix 环境高级编程》第13 章 精灵进程

Syslog为每个事件赋予几个不同的优先级:

LOG_EMERG——紧急情况 
LOG_ALERT——应该被立即改正的问题,如系统数据库破坏
LOG_CRIT——重要情况,如硬盘错误
LOG_ERR——错误
LOG_WARNING——警告信息
LOG_NOTICE——不是错误情况,但是可能需要处理
LOG_INFO——情报信息
LOG_DEBUG——包含情报的信息,通常旨在调试一个程序时使用
#include<stdio.h>
#include<stdlib.h>
#include <syslog.h>

syslog(LOG_INFO, "hello %s","woring");
syslog(LOG_ERR, "hello %s","test");

范例:

#include<stdio.h>
#include<stdlib.h>
#include <syslog.h>

void main(void)
{
    for(int i=0;i<3;i++){
    syslog(LOG_USER|LOG_EMERG,"syslog programming test %d times/n", i);
  }
}

➜ c git:(master) ✗ gcc logtest.c -std=c99
➜ c git:(master) ✗ ./a.out

检验:

tail -f /var/log/syslog

Mar 6 17:37:45 brian a.out: syslog programming test 0 times/n
Mar 6 17:37:45 brian a.out: syslog programming test 1 times/n
Mar 6 17:37:45 briana.out: syslog programming test 2 times/n

 

Ubuntu:
/ect/rsyslog.conf
tail -f /var/log/syslog

Other linux:
/etc/syslog.conf
/etc/syslog-ng/syslog-ng.conf
tail -f /var/log/messages

参考:
c语言库函数syslog--将信息记录至系统日志文件
https://blog.csdn.net/jiangxinyu/article/details/1473356

相关文章: