1SYSLOG(3) Linux Programmer's Manual SYSLOG(3)
2
3
4
6 closelog, openlog, syslog, vsyslog - 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 void vsyslog(int priority, const char *format, va_list ap);
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 vsyslog():
20 Since glibc 2.19:
21 _DEFAULT_SOURCE
22 Glibc 2.19 and earlier:
23 _BSD_SOURCE
24
26 openlog()
27 openlog() opens a connection to the system logger for a program.
28
29 The string pointed to by ident is prepended to every message, and is
30 typically set to the program name. If ident is NULL, the program name
31 is used. (POSIX.1-2008 does not specify the behavior when ident is
32 NULL.)
33
34 The option argument specifies flags which control the operation of
35 openlog() and subsequent calls to syslog(). The facility argument
36 establishes a default to be used if none is specified in subsequent
37 calls to syslog(). The values that may be specified for option and
38 facility are described below.
39
40 The use of openlog() is optional; it will automatically be called by
41 syslog() if necessary, in which case ident will default to NULL.
42
43 syslog() and vsyslog()
44 syslog() generates a log message, which will be distributed by sys‐
45 logd(8).
46
47 The priority argument is formed by ORing together a facility value and
48 a level value (described below). If no facility value is ORed into
49 priority, then the default value set by openlog() is used, or, if there
50 was no preceding openlog() call, a default of LOG_USER is employed.
51
52 The remaining arguments are a format, as in printf(3), and any argu‐
53 ments required by the format, except that the two-character sequence %m
54 will be replaced by the error message string strerror(errno). The for‐
55 mat string need not include a terminating newline character.
56
57 The function vsyslog() performs the same task as syslog() with the dif‐
58 ference that it takes a set of arguments which have been obtained using
59 the stdarg(3) variable argument list macros.
60
61 closelog()
62 closelog() closes the file descriptor being used to write to the system
63 logger. The use of closelog() is optional.
64
65 Values for option
66 The option argument to openlog() is a bit mask constructed by ORing
67 together any of the following values:
68
69 LOG_CONS Write directly to the system console if there is an
70 error while sending to the system logger.
71
72 LOG_NDELAY Open the connection immediately (normally, the connec‐
73 tion is opened when the first message is logged). This
74 may be useful, for example, if a subsequent chroot(2)
75 would make the pathname used internally by the logging
76 facility unreachable.
77
78 LOG_NOWAIT Don't wait for child processes that may have been cre‐
79 ated while logging the message. (The GNU C library does
80 not create a child process, so this option has no effect
81 on Linux.)
82
83 LOG_ODELAY The converse of LOG_NDELAY; opening of the connection is
84 delayed until syslog() is called. (This is the default,
85 and need not be specified.)
86
87 LOG_PERROR (Not in POSIX.1-2001 or POSIX.1-2008.) Also log the
88 message to stderr.
89
90 LOG_PID Include the caller's PID with each message.
91
92 Values for facility
93 The facility argument is used to specify what type of program is log‐
94 ging the message. This lets the configuration file specify that mes‐
95 sages from different facilities will be handled differently.
96
97 LOG_AUTH security/authorization messages
98
99 LOG_AUTHPRIV security/authorization messages (private)
100
101 LOG_CRON clock daemon (cron and at)
102
103 LOG_DAEMON system daemons without separate facility value
104
105 LOG_FTP ftp daemon
106
107 LOG_KERN kernel messages (these can't be generated from user pro‐
108 cesses)
109
110 LOG_LOCAL0 through LOG_LOCAL7
111 reserved for local use
112
113 LOG_LPR line printer subsystem
114
115 LOG_MAIL mail subsystem
116
117 LOG_NEWS USENET news subsystem
118
119 LOG_SYSLOG messages generated internally by syslogd(8)
120
121 LOG_USER (default)
122 generic user-level messages
123
124 LOG_UUCP UUCP subsystem
125
126 Values for level
127 This determines the importance of the message. The levels are, in
128 order of decreasing importance:
129
130 LOG_EMERG system is unusable
131
132 LOG_ALERT action must be taken immediately
133
134 LOG_CRIT critical conditions
135
136 LOG_ERR error conditions
137
138 LOG_WARNING warning conditions
139
140 LOG_NOTICE normal, but significant, condition
141
142 LOG_INFO informational message
143
144 LOG_DEBUG debug-level message
145
146 The function setlogmask(3) can be used to restrict logging to specified
147 levels only.
148
150 For an explanation of the terms used in this section, see
151 attributes(7).
152
153 ┌──────────────────────┬───────────────┬────────────────────┐
154 │Interface │ Attribute │ Value │
155 ├──────────────────────┼───────────────┼────────────────────┤
156 │openlog(), closelog() │ Thread safety │ MT-Safe │
157 ├──────────────────────┼───────────────┼────────────────────┤
158 │syslog(), vsyslog() │ Thread safety │ MT-Safe env locale │
159 └──────────────────────┴───────────────┴────────────────────┘
161 The functions openlog(), closelog(), and syslog() (but not vsyslog())
162 are specified in SUSv2, POSIX.1-2001, and POSIX.1-2008.
163
164 POSIX.1-2001 specifies only the LOG_USER and LOG_LOCAL* values for
165 facility. However, with the exception of LOG_AUTHPRIV and LOG_FTP, the
166 other facility values appear on most UNIX systems.
167
168 The LOG_PERROR value for option is not specified by POSIX.1-2001 or
169 POSIX.1-2008, but is available in most versions of UNIX.
170
172 The argument ident in the call of openlog() is probably stored as-is.
173 Thus, if the string it points to is changed, syslog() may start
174 prepending the changed string, and if the string it points to ceases to
175 exist, the results are undefined. Most portable is to use a string
176 constant.
177
178 Never pass a string with user-supplied data as a format, use the fol‐
179 lowing instead:
180
181 syslog(priority, "%s", string);
182
184 journalctl(1), logger(1), setlogmask(3), syslog.conf(5), syslogd(8)
185
187 This page is part of release 4.15 of the Linux man-pages project. A
188 description of the project, information about reporting bugs, and the
189 latest version of this page, can be found at
190 https://www.kernel.org/doc/man-pages/.
191
192
193
194Linux 2017-09-15 SYSLOG(3)