| 1 | .\" Copyright (c) 1983 Regents of the University of California. |
| 2 | .\" All rights reserved. The Berkeley software License Agreement |
| 3 | .\" specifies the terms and conditions for redistribution. |
| 4 | .\" |
| 5 | .\" @(#)syslog.3 6.1 (Berkeley) %G% |
| 6 | .\" |
| 7 | .TH SYSLOG 3 "" |
| 8 | .UC 5 |
| 9 | .SH NAME |
| 10 | syslog, openlog, closelog, setlogmask \- control system log |
| 11 | .SH SYNOPSIS |
| 12 | .B "#include <syslog.h> |
| 13 | .PP |
| 14 | .B "openlog(ident, logopt, maskpri) |
| 15 | .br |
| 16 | .B "char *ident; |
| 17 | .PP |
| 18 | .B "syslog(priority, message, parameters ... ) |
| 19 | .br |
| 20 | .B "char *message; |
| 21 | .PP |
| 22 | .B "closelog() |
| 23 | .PP |
| 24 | .B "setlogmask(maskpri) |
| 25 | .SH DESCRIPTION |
| 26 | .I Syslog |
| 27 | arranges to write |
| 28 | .I message |
| 29 | onto the system log maintained by |
| 30 | .IR syslogd (8). |
| 31 | The message is tagged with |
| 32 | .IR priority . |
| 33 | The message looks like a |
| 34 | .IR printf (3) |
| 35 | string except that |
| 36 | .B %m |
| 37 | is replaced by the current error message (collected from |
| 38 | .IR errno ). |
| 39 | A trailing newline is added if needed. |
| 40 | This message will be read by |
| 41 | .IR syslogd (8) |
| 42 | and written to the system console, log files, or forwarded to |
| 43 | .I syslogd |
| 44 | on another host as appropriate. |
| 45 | If |
| 46 | .I syslog |
| 47 | cannot pass the message to |
| 48 | .I syslogd |
| 49 | and the message is priority LOG_FAIL or higher, |
| 50 | it attempts to write the message on |
| 51 | .IR /dev/console. |
| 52 | .PP |
| 53 | If special processing is needed, |
| 54 | .I openlog |
| 55 | can be called to initialize the log file. |
| 56 | The parameter |
| 57 | .I ident |
| 58 | is a string that is prepended to every message. |
| 59 | .I Logopt |
| 60 | is a bit field indicating logging options. |
| 61 | Current values for |
| 62 | .I logopt |
| 63 | are: |
| 64 | .IP LOG_PID \w'LOG_ODELAY'u+3 |
| 65 | log the process id with each message: |
| 66 | useful for identifying instantiations of daemons. |
| 67 | .IP LOG_CONS \w'LOG_ODELAY'u+3 |
| 68 | Force writing error messages to the console if unable to send it to |
| 69 | .I syslogd. |
| 70 | This option is safe to use in daemon processes that have no controlling |
| 71 | terminal since |
| 72 | .I syslog |
| 73 | will fork before opening the console. |
| 74 | .IP LOG_ODELAY \w'LOG_ODELAY'u+3 |
| 75 | Delay opening the connection to |
| 76 | .I syslogd |
| 77 | until the first error occurs. Useful for programs that need to manage the |
| 78 | order in which file descriptors are allocated. |
| 79 | .PP |
| 80 | The |
| 81 | .I maskpri |
| 82 | parameter is a mask for screening out low priority messages. |
| 83 | Calls to |
| 84 | .I syslog |
| 85 | with a priority whose corresponding bit in |
| 86 | .I maskpri |
| 87 | is not set are ignored. |
| 88 | The default allows all priorities to be logged. |
| 89 | .PP |
| 90 | .I Closelog |
| 91 | can be used to close the log file. |
| 92 | .PP |
| 93 | .I Setlogmask |
| 94 | sets the log priority mask to |
| 95 | .I maskpri |
| 96 | and returns the previous mask. |
| 97 | Priorities and masks of 0 are ignored. |
| 98 | .SH EXAMPLES |
| 99 | .nf |
| 100 | syslog(LOG_SALERT, "who: internal error 23"); |
| 101 | |
| 102 | openlog("serverftp", LOG_PID, 0); |
| 103 | syslog(LOG_INFO, "Connection from host %d", CallingHost); |
| 104 | .fi |
| 105 | .SH "SEE ALSO" |
| 106 | syslogd(8) |