linux c syslog LOG_CONS off
linux c syslog 控制台不输出

openlog("SEC", LOG_PID, LOG_USER);

使用上面的选项打开控制台就不输出日志了。

可用的参数:
option

The option argument to openlog() is an OR of any of these:
LOG_CONS
Write directly to system console if there is an error while sending to system logger.

LOG_NDELAY

Open the connection immediately (normally, the connection is opened when the first message is logged).

LOG_NOWAIT

Don't wait for child processes that may have been created while logging the message. (The GNU C library does not create a child process, so this option has no effect on Linux.)

LOG_ODELAY

The converse of LOG_NDELAY; opening of the connection is delayed until syslog() is called. (This is the default, and need not be specified.)

LOG_PERROR

(Not in POSIX.1-2001 or POSIX.1-2008.) Print to stderr as well.

LOG_PID

Include PID with each message.

linux c openlog example

Here is an example of openlog, syslog, and closelog:

This example sets the logmask so that debug and informational messages get discarded without ever reaching Syslog. So the second syslog in the example does nothing.

#include <syslog.h>

setlogmask (LOG_UPTO (LOG_NOTICE));

openlog ("exampleprog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);

syslog (LOG_NOTICE, "Program started by User %d", getuid ());
syslog (LOG_INFO, "A tree falls in a forest");

closelog ();
本文链接地址:https://const.net.cn/404.html

标签: linux

添加新评论