Commit | Line | Data |
---|---|---|
609b3d57 KM |
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 | .\" | |
6a71ef00 | 5 | .\" @(#)syslog.3 6.6 (Berkeley) %G% |
609b3d57 | 6 | .\" |
ed6316b8 | 7 | .TH SYSLOG 3 "" |
609b3d57 KM |
8 | .UC 5 |
9 | .SH NAME | |
ed6316b8 | 10 | syslog, openlog, closelog, setlogmask \- control system log |
609b3d57 KM |
11 | .SH SYNOPSIS |
12 | .B "#include <syslog.h> | |
13 | .PP | |
be78fd26 | 14 | .B "openlog(ident, logopt, facility) |
609b3d57 KM |
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() | |
ed6316b8 KM |
23 | .PP |
24 | .B "setlogmask(maskpri) | |
609b3d57 KM |
25 | .SH DESCRIPTION |
26 | .I Syslog | |
ed6316b8 | 27 | arranges to write |
609b3d57 KM |
28 | .I message |
29 | onto the system log maintained by | |
ed6316b8 | 30 | .IR syslogd (8). |
609b3d57 KM |
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 | |
ed6316b8 KM |
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. | |
be78fd26 EA |
45 | .PP |
46 | Priorities are encoded as a | |
47 | .I facility | |
48 | and a | |
49 | .IR level . | |
50 | The facility describes the part of the system | |
51 | generating the message. | |
52 | The level is selected from an ordered list: | |
53 | .IP LOG_EMERG \w'LOG_WARNING'u+3 | |
54 | A panic condition. | |
55 | This is normally broadcast to all users. | |
56 | .IP LOG_ALERT \w'LOG_WARNING'u+3 | |
57 | A condition that should be corrected immediately, | |
58 | such as a corrupted system database. | |
59 | .IP LOG_CRIT \w'LOG_WARNING'u+3 | |
60 | Critical conditions, | |
61 | e.g., hard device errors. | |
62 | .IP LOG_ERR \w'LOG_WARNING'u+3 | |
63 | Errors. | |
64 | .IP LOG_WARNING \w'LOG_WARNING'u+3 | |
65 | Warning messages. | |
66 | .IP LOG_NOTICE \w'LOG_WARNING'u+3 | |
67 | Conditions that are not error conditions, | |
68 | but should possibly be handled specially. | |
69 | .IP LOG_INFO \w'LOG_WARNING'u+3 | |
70 | Informational messages. | |
71 | .IP LOG_DEBUG \w'LOG_WARNING'u+3 | |
72 | Messages that contain information | |
73 | normally of use only when debugging a program. | |
74 | .PP | |
ed6316b8 KM |
75 | If |
76 | .I syslog | |
77 | cannot pass the message to | |
6a71ef00 MK |
78 | .IR syslogd , |
79 | it will attempt to write the message on | |
80 | .I /dev/console | |
81 | if the LOG_CONS option is set (see below). | |
609b3d57 KM |
82 | .PP |
83 | If special processing is needed, | |
84 | .I openlog | |
85 | can be called to initialize the log file. | |
ed6316b8 | 86 | The parameter |
609b3d57 | 87 | .I ident |
ed6316b8 KM |
88 | is a string that is prepended to every message. |
89 | .I Logopt | |
90 | is a bit field indicating logging options. | |
91 | Current values for | |
92 | .I logopt | |
93 | are: | |
be78fd26 | 94 | .IP LOG_PID \w'LOG_WARNING'u+3 |
609b3d57 KM |
95 | log the process id with each message: |
96 | useful for identifying instantiations of daemons. | |
be78fd26 EA |
97 | .IP LOG_CONS \w'LOG_WARNING'u+3 |
98 | Force writing messages to the console if unable to send it to | |
ed6316b8 KM |
99 | .I syslogd. |
100 | This option is safe to use in daemon processes that have no controlling | |
101 | terminal since | |
102 | .I syslog | |
103 | will fork before opening the console. | |
0c9a57bf | 104 | .IP LOG_NDELAY \w'LOG_WARNING'u+3 |
6a71ef00 | 105 | Open the connection to |
ed6316b8 | 106 | .I syslogd |
0c9a57bf EA |
107 | immediately. |
108 | Normally the open is delayed | |
be78fd26 EA |
109 | until the first message is logged. |
110 | Useful for programs that need to manage the | |
ed6316b8 | 111 | order in which file descriptors are allocated. |
6a71ef00 MK |
112 | .IP LOG_NOWAIT \w'LOG_WARNING'u+3 |
113 | Don't wait for children forked to log messages on the console. | |
114 | This option should be used by processes that enable notification | |
115 | of child termination via SIGCHLD, as | |
116 | .I syslog | |
117 | may otherwise block waiting for a child whose exit status has already | |
118 | been collected. | |
ed6316b8 KM |
119 | .PP |
120 | The | |
be78fd26 | 121 | .I facility |
6a71ef00 | 122 | parameter encodes a default facility to be assigned to all messages |
be78fd26 EA |
123 | that do not have an explicit facility encoded: |
124 | .IP LOG_KERN \w'LOG_WARNING'u+3 | |
125 | Messages generated by the kernel. | |
126 | These cannot be generated by any user processes. | |
127 | .IP LOG_USER \w'LOG_WARNING'u+3 | |
128 | Messages generated by random user processes. | |
6a71ef00 | 129 | This is the default facility identifier if none is specified. |
be78fd26 EA |
130 | .IP LOG_MAIL \w'LOG_WARNING'u+3 |
131 | The mail system. | |
132 | .IP LOG_DAEMON \w'LOG_WARNING'u+3 | |
133 | System daemons, such as | |
a7aaa6ab | 134 | .IR ftpd (8), |
be78fd26 EA |
135 | .IR routed (8), |
136 | etc. | |
137 | .IP LOG_AUTH \w'LOG_WARNING'u+3 | |
138 | The authorization system: | |
139 | .IR login (1), | |
140 | .IR su (1), | |
141 | .IR getty (8), | |
142 | etc. | |
a4e75007 EA |
143 | .IP LOG_LPR \w'LOG_WARNING'u+3 |
144 | The line printer spooling system: | |
145 | .IR lpr (1), | |
146 | .IR lpc (8), | |
147 | .IR lpd (8), | |
148 | etc. | |
be78fd26 EA |
149 | .IP LOG_LOCAL0 \w'LOG_WARNING'u+3 |
150 | Reserved for local use. | |
151 | Similarly for LOG_LOCAL1 through LOG_LOCAL7. | |
609b3d57 KM |
152 | .PP |
153 | .I Closelog | |
154 | can be used to close the log file. | |
ed6316b8 KM |
155 | .PP |
156 | .I Setlogmask | |
157 | sets the log priority mask to | |
158 | .I maskpri | |
159 | and returns the previous mask. | |
be78fd26 EA |
160 | Calls to |
161 | .I syslog | |
6a71ef00 | 162 | with a priority not set in |
be78fd26 EA |
163 | .I maskpri |
164 | are rejected. | |
6a71ef00 MK |
165 | The mask for an individual priority |
166 | .I pri | |
167 | is calculated by the macro LOG_MASK(\fIpri\fP); | |
168 | the mask for all priorities up to and including | |
169 | .I toppri | |
170 | is given by the macro LOG_UPTO(\fItoppri\fP). | |
be78fd26 | 171 | The default allows all priorities to be logged. |
609b3d57 KM |
172 | .SH EXAMPLES |
173 | .nf | |
be78fd26 | 174 | syslog(LOG_ALERT, "who: internal error 23"); |
609b3d57 | 175 | |
be78fd26 | 176 | openlog("ftpd", LOG_PID, LOG_DAEMON); |
6a71ef00 | 177 | setlogmask(LOG_UPTO(LOG_ERR)); |
609b3d57 | 178 | syslog(LOG_INFO, "Connection from host %d", CallingHost); |
be78fd26 EA |
179 | |
180 | syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); | |
609b3d57 | 181 | .fi |
ed6316b8 | 182 | .SH "SEE ALSO" |
be78fd26 | 183 | logger(1), |
ed6316b8 | 184 | syslogd(8) |