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 | .\" | |
a7aaa6ab | 5 | .\" @(#)syslog.3 6.5 (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 | |
78 | .I syslogd | |
be78fd26 | 79 | and the message is priority LOG_ERR or higher, |
ed6316b8 KM |
80 | it attempts to write the message on |
81 | .IR /dev/console. | |
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 EA |
104 | .IP LOG_NDELAY \w'LOG_WARNING'u+3 |
105 | Opening 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 KM |
111 | order in which file descriptors are allocated. |
112 | .PP | |
113 | The | |
be78fd26 EA |
114 | .I facility |
115 | parameter is encodes a default facility to be assigned to all messages | |
116 | that do not have an explicit facility encoded: | |
117 | .IP LOG_KERN \w'LOG_WARNING'u+3 | |
118 | Messages generated by the kernel. | |
119 | These cannot be generated by any user processes. | |
120 | .IP LOG_USER \w'LOG_WARNING'u+3 | |
121 | Messages generated by random user processes. | |
122 | This is the default if none is specified. | |
123 | .IP LOG_MAIL \w'LOG_WARNING'u+3 | |
124 | The mail system. | |
125 | .IP LOG_DAEMON \w'LOG_WARNING'u+3 | |
126 | System daemons, such as | |
a7aaa6ab | 127 | .IR ftpd (8), |
be78fd26 EA |
128 | .IR routed (8), |
129 | etc. | |
130 | .IP LOG_AUTH \w'LOG_WARNING'u+3 | |
131 | The authorization system: | |
132 | .IR login (1), | |
133 | .IR su (1), | |
134 | .IR getty (8), | |
135 | etc. | |
a4e75007 EA |
136 | .IP LOG_LPR \w'LOG_WARNING'u+3 |
137 | The line printer spooling system: | |
138 | .IR lpr (1), | |
139 | .IR lpc (8), | |
140 | .IR lpd (8), | |
141 | etc. | |
be78fd26 EA |
142 | .IP LOG_LOCAL0 \w'LOG_WARNING'u+3 |
143 | Reserved for local use. | |
144 | Similarly for LOG_LOCAL1 through LOG_LOCAL7. | |
609b3d57 KM |
145 | .PP |
146 | .I Closelog | |
147 | can be used to close the log file. | |
ed6316b8 KM |
148 | .PP |
149 | .I Setlogmask | |
150 | sets the log priority mask to | |
151 | .I maskpri | |
152 | and returns the previous mask. | |
be78fd26 EA |
153 | Calls to |
154 | .I syslog | |
155 | with a priority lower than | |
156 | .I maskpri | |
157 | are rejected. | |
158 | The default allows all priorities to be logged. | |
609b3d57 KM |
159 | .SH EXAMPLES |
160 | .nf | |
be78fd26 | 161 | syslog(LOG_ALERT, "who: internal error 23"); |
609b3d57 | 162 | |
be78fd26 | 163 | openlog("ftpd", LOG_PID, LOG_DAEMON); |
609b3d57 | 164 | syslog(LOG_INFO, "Connection from host %d", CallingHost); |
be78fd26 EA |
165 | |
166 | syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); | |
609b3d57 | 167 | .fi |
ed6316b8 | 168 | .SH "SEE ALSO" |
be78fd26 | 169 | logger(1), |
ed6316b8 | 170 | syslogd(8) |