1SYSLOG(3) Linux Programmer's Manual SYSLOG(3)
2
3
4
6 closelog, openlog, syslog - send messages to the system logger
7
9 #include <syslog.h>
10
11 void openlog(const char *ident, int option, int facility);
12 void syslog(int priority, const char *format, ...);
13 void closelog(void);
14
15 #define _BSD_SOURCE
16 #include <stdarg.h>
17
18 void vsyslog(int priority, const char *format, va_list ap);
19
21 closelog() closes the descriptor being used to write to the system log‐
22 ger. The use of closelog() is optional.
23
24 openlog() opens a connection to the system logger for a program. The
25 string pointed to by ident is prepended to every message, and is typi‐
26 cally set to the program name. The option argument specifies flags
27 which control the operation of openlog() and subsequent calls to sys‐
28 log(). The facility argument establishes a default to be used if none
29 is specified in subsequent calls to syslog(). Values for option and
30 facility are given below. The use of openlog() is optional; it will
31 automatically be called by syslog() if necessary, in which case ident
32 will default to NULL.
33
34 syslog() generates a log message, which will be distributed by sys‐
35 logd(8). The priority argument is formed by ORing the facility and the
36 level values (explained below). The remaining arguments are a format,
37 as in printf(3) and any arguments required by the format, except that
38 the two character sequence %m will be replaced by the error message
39 string strerror(errno). A trailing newline may be added if needed.
40
41 The function vsyslog() performs the same task as syslog() with the dif‐
42 ference that it takes a set of arguments which have been obtained using
43 the stdarg(3) variable argument list macros.
44
46 This section lists the parameters used to set the values of option,
47 facility, and priority.
48
49 option
50 The option argument to openlog() is an OR of any of these:
51
52 LOG_CONS
53 Write directly to system console if there is an error while
54 sending to system logger.
55
56 LOG_NDELAY
57 Open the connection immediately (normally, the connection is
58 opened when the first message is logged).
59
60 LOG_NOWAIT
61 Don't wait for child processes that may have been created while
62 logging the message. (The GNU C library does not create a child
63 process, so this option has no effect on Linux.)
64
65 LOG_ODELAY
66 The converse of LOG_NDELAY; opening of the connection is delayed
67 until syslog() is called. (This is the default, and need not be
68 specified.)
69
70 LOG_PERROR
71 (Not in POSIX.1-2001.) Print to stderr as well.
72
73 LOG_PID
74 Include PID with each message.
75
76 facility
77 The facility argument is used to specify what type of program is log‐
78 ging the message. This lets the configuration file specify that mes‐
79 sages from different facilities will be handled differently.
80
81 LOG_AUTH
82 security/authorization messages (DEPRECATED Use LOG_AUTHPRIV
83 instead)
84
85 LOG_AUTHPRIV
86 security/authorization messages (private)
87
88 LOG_CRON
89 clock daemon (cron and at)
90
91 LOG_DAEMON
92 system daemons without separate facility value
93
94 LOG_FTP
95 ftp daemon
96
97 LOG_KERN
98 kernel messages
99
100 LOG_LOCAL0 through LOG_LOCAL7
101 reserved for local use
102
103 LOG_LPR
104 line printer subsystem
105
106 LOG_MAIL
107 mail subsystem
108
109 LOG_NEWS
110 USENET news subsystem
111
112 LOG_SYSLOG
113 messages generated internally by syslogd
114
115 LOG_USER (default)
116 generic user-level messages
117
118 LOG_UUCP
119 UUCP subsystem
120
121
122 level
123 This determines the importance of the message. The levels are, in
124 order of decreasing importance:
125
126 LOG_EMERG
127 system is unusable
128
129 LOG_ALERT
130 action must be taken immediately
131
132 LOG_CRIT
133 critical conditions
134
135 LOG_ERR
136 error conditions
137
138 LOG_WARNING
139 warning conditions
140
141 LOG_NOTICE
142 normal, but significant, condition
143
144 LOG_INFO
145 informational message
146
147 LOG_DEBUG
148 debug-level message
149
150 The function setlogmask(3) can be used to restrict logging to specified
151 levels only.
152
154 The functions openlog(), closelog(), and syslog() (but not vsyslog())
155 are specified in SUSv2 and POSIX.1-2001. POSIX.1-2001 specifies only
156 the LOG_USER and LOG_LOCAL* values for facility. However, with the
157 exception of LOG_AUTHPRIV and LOG_FTP, the other facility values appear
158 on most Unix systems. The LOG_PERROR value for option is not specified
159 by POSIX.1-2001, but is available in most versions of Unix.
160
162 A syslog() function call appeared in 4.2BSD. 4.3BSD documents open‐
163 log(), syslog(), closelog(), and setlogmask(). 4.3BSD-Reno also docu‐
164 ments vsyslog(). Of course early v* functions used the <varargs.h>
165 mechanism, which is not compatible with <stdarg.h>.
166
168 The parameter ident in the call of openlog() is probably stored as-is.
169 Thus, if the string it points to is changed, syslog() may start
170 prepending the changed string, and if the string it points to ceases to
171 exist, the results are undefined. Most portable is to use a string
172 constant.
173
174 Never pass a string with user-supplied data as a format, use
175 syslog(priority, "%s", string);
176 instead.
177
179 logger(1), setlogmask(3), syslog.conf(5), feature_test_macros(7), sys‐
180 logd(8)
181
182
183
184Linux 2002-01-03 SYSLOG(3)