Is there a way to redirect syslog messages to stdout?

北战南征 提交于 2019-12-01 03:53:48
Brandon Yates

As suggested in the comments by maverik, I wrote a wrapper around syslog that determines whether to send the output to the log or console. Here it is in case anyone ever needs this.

void mylog (int level, const char *format, ...)
{
    va_list args;
    va_start (args, format);

    if (remote)
    {
        vsyslog(level, format, args);
    }   
    else
    {
        if (level == LOG_DEBUG)
            vsyslog(level, format, args);
        else
            vprintf(format, args);
    }
    va_end(args);
}

As GNU-specific solution I would suggest using openlog(NULL, LOG_PERROR, your_facility). Not customizable(just duplicate on stderr).

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