1syslog(3)                  Library Functions Manual                  syslog(3)
2
3
4

NAME

6       closelog, openlog, syslog, vsyslog - send messages to the system logger
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <syslog.h>
13
14       void openlog(const char *ident, int option, int facility);
15       void syslog(int priority, const char *format, ...);
16       void closelog(void);
17
18       void vsyslog(int priority, const char *format, va_list ap);
19
20   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21
22       vsyslog():
23           Since glibc 2.19:
24               _DEFAULT_SOURCE
25           glibc 2.19 and earlier:
26               _BSD_SOURCE
27

DESCRIPTION

29   openlog()
30       openlog() opens a connection to the system logger for a program.
31
32       The  string  pointed  to by ident is prepended to every message, and is
33       typically set to the program name.  If ident is NULL, the program  name
34       is  used.   (POSIX.1-2008  does  not specify the behavior when ident is
35       NULL.)
36
37       The option argument specifies flags  which  control  the  operation  of
38       openlog()  and subsequent calls to syslog().  The facility argument es‐
39       tablishes a default to be used if none is specified in subsequent calls
40       to  syslog().  The values that may be specified for option and facility
41       are described below.
42
43       The use of openlog() is optional; it will automatically  be  called  by
44       syslog() if necessary, in which case ident will default to NULL.
45
46   syslog() and vsyslog()
47       syslog()  generates  a  log  message, which will be distributed by sys‐
48       logd(8).
49
50       The priority argument is formed by ORing together a facility value  and
51       a  level  value  (described  below).  If no facility value is ORed into
52       priority, then the default value set by openlog() is used, or, if there
53       was no preceding openlog() call, a default of LOG_USER is employed.
54
55       The  remaining  arguments  are a format, as in printf(3), and any argu‐
56       ments required by the format, except that the two-character sequence %m
57       will be replaced by the error message string strerror(errno).  The for‐
58       mat string need not include a terminating newline character.
59
60       The function vsyslog() performs the same task as syslog() with the dif‐
61       ference that it takes a set of arguments which have been obtained using
62       the stdarg(3) variable argument list macros.
63
64   closelog()
65       closelog() closes the file descriptor being used to write to the system
66       logger.  The use of closelog() is optional.
67
68   Values for option
69       The option argument to openlog() is a bit mask constructed by ORing to‐
70       gether any of the following values:
71
72       LOG_CONS       Write directly to the system console if there is an  er‐
73                      ror while sending to the system logger.
74
75       LOG_NDELAY     Open  the  connection immediately (normally, the connec‐
76                      tion is opened when the first message is logged).   This
77                      may  be  useful,  for example, if a subsequent chroot(2)
78                      would make the pathname used internally by  the  logging
79                      facility unreachable.
80
81       LOG_NOWAIT     Don't  wait  for child processes that may have been cre‐
82                      ated while logging the message.  (The GNU C library does
83                      not create a child process, so this option has no effect
84                      on Linux.)
85
86       LOG_ODELAY     The converse of LOG_NDELAY; opening of the connection is
87                      delayed until syslog() is called.  (This is the default,
88                      and need not be specified.)
89
90       LOG_PERROR     (Not in POSIX.1-2001 or  POSIX.1-2008.)   Also  log  the
91                      message to stderr.
92
93       LOG_PID        Include the caller's PID with each message.
94
95   Values for facility
96       The  facility  argument is used to specify what type of program is log‐
97       ging the message.  This lets the configuration file specify  that  mes‐
98       sages from different facilities will be handled differently.
99
100       LOG_AUTH       security/authorization messages
101
102       LOG_AUTHPRIV   security/authorization messages (private)
103
104       LOG_CRON       clock daemon (cron and at)
105
106       LOG_DAEMON     system daemons without separate facility value
107
108       LOG_FTP        ftp daemon
109
110       LOG_KERN       kernel messages (these can't be generated from user pro‐
111                      cesses)
112
113       LOG_LOCAL0 through LOG_LOCAL7
114                      reserved for local use
115
116       LOG_LPR        line printer subsystem
117
118       LOG_MAIL       mail subsystem
119
120       LOG_NEWS       USENET news subsystem
121
122       LOG_SYSLOG     messages generated internally by syslogd(8)
123
124       LOG_USER (default)
125                      generic user-level messages
126
127       LOG_UUCP       UUCP subsystem
128
129   Values for level
130       This determines the importance of the message.  The levels are, in  or‐
131       der of decreasing importance:
132
133       LOG_EMERG      system is unusable
134
135       LOG_ALERT      action must be taken immediately
136
137       LOG_CRIT       critical conditions
138
139       LOG_ERR        error conditions
140
141       LOG_WARNING    warning conditions
142
143       LOG_NOTICE     normal, but significant, condition
144
145       LOG_INFO       informational message
146
147       LOG_DEBUG      debug-level message
148
149       The function setlogmask(3) can be used to restrict logging to specified
150       levels only.
151

ATTRIBUTES

153       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
154       tributes(7).
155
156       ┌─────────────────────────────────┬───────────────┬────────────────────┐
157Interface                        Attribute     Value              
158       ├─────────────────────────────────┼───────────────┼────────────────────┤
159openlog(), closelog()            │ Thread safety │ MT-Safe            │
160       ├─────────────────────────────────┼───────────────┼────────────────────┤
161syslog(), vsyslog()              │ Thread safety │ MT-Safe env locale │
162       └─────────────────────────────────┴───────────────┴────────────────────┘
163

STANDARDS

165       syslog()
166       openlog()
167       closelog()
168              POSIX.1-2008.
169
170       vsyslog()
171              None.
172

HISTORY

174       syslog()
175              4.2BSD, SUSv2, POSIX.1-2001.
176
177       openlog()
178       closelog()
179              4.3BSD, SUSv2, POSIX.1-2001.
180
181       vsyslog()
182              4.3BSD-Reno.
183
184       POSIX.1-2001  specifies only the LOG_USER and LOG_LOCAL* values for fa‐
185       cility.  However, with the exception of LOG_AUTHPRIV and  LOG_FTP,  the
186       other facility values appear on most UNIX systems.
187
188       The  LOG_PERROR  value  for  option is not specified by POSIX.1-2001 or
189       POSIX.1-2008, but is available in most versions of UNIX.
190

NOTES

192       The argument ident in the call of openlog() is probably  stored  as-is.
193       Thus,  if  the  string  it  points  to  is  changed, syslog() may start
194       prepending the changed string, and if the string it points to ceases to
195       exist,  the  results  are  undefined.  Most portable is to use a string
196       constant.
197
198       Never pass a string with user-supplied data as a format, use  the  fol‐
199       lowing instead:
200
201           syslog(priority, "%s", string);
202

SEE ALSO

204       journalctl(1), logger(1), setlogmask(3), syslog.conf(5), syslogd(8)
205
206
207
208Linux man-pages 6.04              2023-03-30                         syslog(3)
Impressum