1、void openlog(const char *ident, int option, int facility);
第一個參數ident将是一個标記,ident所表示的字元串将固定地加在每行日志的前面以辨別這個日志,通常就寫成目前程式的名稱以作标記。
第二個參數option是下列值取與運算的結果:LOG_CONS,LOG_NDELAY, LOG_NOWAIT, LOG_ODELAY, LOG_PERROR,LOG_PID,各值意義請參考man openlog手冊:
LOG_CONS
Writedirectly to system console if there is an error while sending tosystem logger.
LOG_NDELAY
Openthe connection immediately (normally, the connection is opened whenthe first message is logged).
LOG_NOWAIT
Don’t wait for childprocesses that may have been created while logging themessage. (The GNU C library does not createa child process, so this option has no effect onLinux.)
LOG_ODELAY
The converseof LOG_NDELAY; opening of the connection is delayed until syslog()is called. (This is the default, and need not be specified.)
LOG_PERROR
(Notin SUSv3.) Print to stderr as well.
LOG_PID
IncludePID with each message.
第三個參數facility指明記錄日志的程式的類型。
The facility argument is used to specify what type ofprogram is logging the message.
This lets the configuration file specify thatmessages from different facilities will be
handled differently.
LOG_AUTH security/authorization messages (DEPRECATED Use LOG_AUTHPRIVinstead)
LOG_AUTHPRIV security/authorization messages (private)
LOG_CRON clock daemon (cron and at)
LOG_DAEMON system daemons without separate facility value
LOG_FTP ftp daemon
LOG_KERN kernel messages (these can't be generage from user processes)
LOG_LOCAL0 through LOG_LOCAL7
reserved for local use
LOG_LPR line printer subsystem
LOG_MAIL mail subsystem
LOG_NEWS USENET news subsystem
LOG_SYSLOG messages generated internally by syslogd(8)
LOG_USER (default)
generic user-level messages
LOG_UUCP UUCP subsystem
2、void syslog(int priority, const char *format, ...);
This determines the importance of the message. The levels are, in order of decreasing
importance:
LOG_EMERG system is unusable
LOG_ALERT action must be taken immediately
LOG_CRIT critical conditions
LOG_ERR error conditions
LOG_WARNING warning conditions
LOG_NOTICE normal, but significant, condition
LOG_INFO informational message
LOG_DEBUG debug-level message
The function setlogmask(3) can be used to restrict logging tospecified levels only.
3、int setlogmask(int maskpri);
程序有一個日志優先級掩碼,該掩碼決定哪些調用syslog(3)可能被記錄。所有其他調用都将被忽略。日志是為在掩碼中設定相應位的優先級啟用的。最初的掩碼是這樣的,日志是為所有優先級啟用的。
setlogmask()函數為目前的程序設定這個日志掩碼,并傳回先前的掩碼。如果掩碼參數為0,那麼目前的日志掩碼不會被修改。
這8個優先級分别是LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO and LOG_DEBUG.與優先級p相對應的位是LOG_MASK(p)。一些系統還提供了一個宏LOG_UPTO(p),以在上面的清單中包括p的所有優先級。
4、調用openlog是可選擇的。如果不調用openlog,則在第一次調用syslog時,自動調用openlog。調用closelog也是可選擇的,它隻是關閉被用于與syslog守護程序通信的描述符。調用openlog使我們可以指定一個ident,以後, 此ident 将被加至每則記錄消息中。
5、代碼示例