Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 2.92 KB

File metadata and controls

84 lines (63 loc) · 2.92 KB

English | 中文版

Daemon Process

[TOC]

System Logging

Logging Messages

#include <syslog.h>
void syslog(int priority, const char *message, ...);
  • priority priority level Composed of level and facility:

    level Value Description
    LOG_EMERG 0 System unusable (highest)
    LOG_ALERT 1 Action must be taken immediately
    LOG_CRIT 2 Critical conditions
    LOG_ERR 3 Error conditions
    LOG_WARNING 4 Warning conditions
    LOG_NOTICE 5 Normal but significant (default)
    LOG_INFO 6 Informational messages
    LOG_DEBUG 7 Debug-level messages (lowest)
    facility Description
    LOG_AUTH Security/authorization
    LOG_AUTHPRIV Security/authorization (private)
    LOG_CRON cron daemon
    LOG_DAEMON System daemons
    LOG_FTP FTP daemon
    LOG_KERN Kernel messages
    LOG_LOCAL0 Local use
    LOG_LOCAL1 Local use
    LOG_LOCAL2 Local use
    LOG_LOCAL3 Local use
    LOG_LOCAL4 Local use
    LOG_LOCAL5 Local use
    LOG_LOCAL6 Local use
    LOG_LOCAL7 Local use
    LOG_LPR Line printer subsystem
    LOG_MAIL Mail system
    LOG_NEWS Network news system
    LOG_SYSLOG Messages generated by syslogd
    LOG_USER User-level messages (default)
    LOG_UUCP UUCP system
  • message formatted string;

Log messages from daemon processes.

Open/Close Log

#include <syslog.h>
void openlog(const char *ident, int options, int facility);
void closelog(void);
  • ident string prefixed to each log message by syslog (usually the program name);

  • options options

    options Description
    LOG_CONS Log to console if unable to send to syslogd daemon.
    LOG_NDELAY Open immediately, create socket right away.
    LOG_PERROR Send to syslogd and also log to standard error.
    LOG_PID Log process ID with each message.
  • facility

Open/close log (by default, openlog does not immediately create a Unix domain socket; it is created on the first call to syslog. This can be changed by setting LOG_NDELAY).

References

[1] (US) W. Richard Stevens, (US) Bill Fenner, (US) Andrew M Rudoff. Unix Network Programming Volume 1: The Sockets Networking API. 3rd Edition