使用rsyslog编程,产生trace信息,记录到日志中

参考:http://blog.csdn.net/nowayings/article/details/38926501

https://www.cnblogs.com/bonelee/p/6234647.html

打印到日志中:

代码如下

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

int main(){
        FILE*f;
        f = fopen("abc","r");
        if(!f){
                syslog(LOG_ERR|LOG_USER,"test -%m/n");
        }
}

配置如下:添加第2行部分。

ubuntu@ubuntu-vm:~/workspace/log$ vim /etc/rsyslog.d/30-debug.conf

*.debug         /var/log/mydebug.log
user.*          -/var/log/user.log
:msg,contains, "logger" ~

运行代码:

ubuntu@ubuntu-vm:~/workspace/log$ ./a.out

ubuntu@ubuntu-vm:~/workspace/log$ cat  /var/log/user.log 
Nov 25 15:30:21 ubuntu-vm a.out: test -No such file or directory/n
Nov 25 15:42:59 ubuntu-vm a.out: test -No such file or directory/n

 



posted @ 2017-11-25 16:28  于光远  阅读(412)  评论(0编辑  收藏  举报