The following example shows a basic LOG_ALERT message.
The syslog() call logs a message at priority LOG_ALERT.
The FTP daemon ftpd makes a call to openlog() to announce that all messages it logs should have the identifying string, ftpd. It also announces that messages should be treated by syslogd() in the same way that other messages from system daemons are treated, and should include the process ID of the process logging the message.
The FTP daemon then makes a call to setlogmask() to indicate that only messages with priorities from LOG_EMERG through LOG_ERR should be logged. Messages with any other priority will not be logged.
The FTP daemon then calls syslog() to log a message at priority LOG_INFO.
syslog(LOG_ALERT, "who: internal error 23"); openlog("ftpd", LOG_PID, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host %d", CallingHost);
A utility written locally would use the following call to syslog() to log a message at priority LOG_INFO. The message would be treated by syslogd() in the same way that other messages to the facility LOG_LOCAL2 are treated:
syslog(LOG_INFO|LOG_LOCAL2, "error: %m");