How to configure syslog so that an applications log goes to a specific file

只愿长相守 提交于 2019-12-12 08:23:32

问题


I have an application myapp which should send log files only to /var/log/myapp.log. myapp is written in C++. The following sample code, sends the logs to /var/log/syslog only. My os is Linux - Ubuntu 12.04 - to be specific. I also found that my machine has rsyslog than syslog installed.

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

int main(void) {
    openlog("myapp", LOG_PID|LOG_CONS, LOG_USER);
    syslog(LOG_INFO, "abc 10");
    closelog();
    return 0;
}

回答1:


According to the syslog(3) manpage, the first parameter for openlog() sets a prefix for log messages, not a filename. You can use a facility like LOG_LOCAL0 to flag your output and then configure syslogd using /etc/syslog.conf to send those logs to the file of your desire.



来源:https://stackoverflow.com/questions/10376020/how-to-configure-syslog-so-that-an-applications-log-goes-to-a-specific-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!