Linux syslog 编程

2017-12-19  本文已影响88人  louyang

GNU C库提供了下述 syslog 相关API:

# cat syslog-example.c

#include <syslog.h>

int main()
{
    openlog(0, 0, 0);
    syslog(LOG_NOTICE, "this is a debug msg");
    syslog(LOG_INFO, "this is an info msg");
    syslog(LOG_ERR, "this is an error msg");
    closelog();
}
# gcc syslog-example.c -o syslog-example && ./syslog-example && journalctl -f
-- Logs begin at Tue 2017-12-19 02:10:07 EET. --
...
Dec 19 08:11:18 euca-10-254-36-5.eucalyptus.internal syslog-example[1960]: this is a debug msg
Dec 19 08:11:18 euca-10-254-36-5.eucalyptus.internal syslog-example[1960]: this is an info msg
Dec 19 08:11:18 euca-10-254-36-5.eucalyptus.internal syslog-example[1960]: this is an error msg
参考

https://www.gnu.org/software/libc/manual/html_node/Submitting-Syslog-Messages.html

上一篇下一篇

猜你喜欢

热点阅读