Next: syslog; vsyslog, Up: Submitting Syslog Messages
The symbols referred to in this section are declared in the file syslog.h.
int facility)
openlogopens or reopens a connection to Syslog in preparation for submitting messages.ident is an arbitrary identification string which future
sysloginvocations will prefix to each message. This is intended to identify the source of the message, and people conventionally set it to the name of the program that will submit the messages.
openlogmay or may not open the /dev/log socket, depending on option. If it does, it tries to open it and connect it as a stream socket. If that doesn't work, it tries to open it and connect it as a datagram socket. The socket has the “Close on Exec” attribute, so the kernel will close it if the process performs an exec.You don't have to use
openlog. If you callsyslogwithout having calledopenlog,syslogjust opens the connection implicitly and uses defaults for the information in ident and options.options is a bit string, with the bits as defined by the following single bit masks:
LOG_PERROR- If on,
openlogsets up the connection so that anysyslogon this connection writes its message to the calling process' Standard Error stream in addition to submitting it to Syslog. If off,syslogdoes not write the message to Standard Error.LOG_CONS- If on,
openlogsets up the connection so that asyslogon this connection that fails to submit a message to Syslog writes the message instead to system console. If off,syslogdoes not write to the system console (but of course Syslog may write messages it receives to the console).LOG_PID- When on,
openlogsets up the connection so that asyslogon this connection inserts the calling process' Process ID (PID) into the message. When off,openlogdoes not insert the PID.LOG_NDELAY- When on,
openlogopens and connects the /dev/log socket. When off, a futuresyslogcall must open and connect the socket.Portability note: In early systems, the sense of this bit was exactly the opposite.
LOG_ODELAY- This bit does nothing. It exists for backward compatibility.
If any other bit in options is on, the result is undefined.
facility is the default facility code for this connection. A
syslogon this connection that specifies default facility causes this facility to be associated with the message. Seesyslogfor possible values. A value of zero means the default default, which isLOG_USER.If a Syslog connection is already open when you call
openlog,openlog“reopens” the connection. Reopening is like opening except that if you specify zero for the default facility code, the default facility code simply remains unchanged and if you specify LOG_NDELAY and the socket is already open and connected,openlogjust leaves it that way.