1SYSLOG(3)                  Linux Programmer's Manual                 SYSLOG(3)
2
3
4

NAME

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

SYNOPSIS

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       #include <stdarg.h>
16
17       void vsyslog(int priority, const char *format, va_list ap);
18
19   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21       vsyslog(): _BSD_SOURCE
22

DESCRIPTION

24       closelog() closes the descriptor being used to write to the system log‐
25       ger.  The use of closelog() is optional.
26
27       openlog() opens a connection to the system logger for a  program.   The
28       string  pointed to by ident is prepended to every message, and is typi‐
29       cally set to the program name.  If ident is NULL, the program  name  is
30       used.  (POSIX.1-2008 does not specify the behavior when ident is NULL.)
31
32       The  option  argument  specifies  flags  which control the operation of
33       openlog() and subsequent calls  to  syslog().   The  facility  argument
34       establishes  a  default  to  be used if none is specified in subsequent
35       calls to syslog().  Values for option and  facility  are  given  below.
36       The  use  of  openlog() is optional; it will automatically be called by
37       syslog() if necessary, in which case ident will default to NULL.
38
39       syslog() generates a log message, which will  be  distributed  by  sys‐
40       logd(8).  The priority argument is formed by ORing the facility and the
41       level values (explained below).  The remaining arguments are a  format,
42       as  in  printf(3) and any arguments required by the format, except that
43       the two character sequence %m will be replaced  by  the  error  message
44       string strerror(errno).  A trailing newline may be added if needed.
45
46       The function vsyslog() performs the same task as syslog() with the dif‐
47       ference that it takes a set of arguments which have been obtained using
48       the stdarg(3) variable argument list macros.
49
50       The  subsections  below  list  the parameters used to set the values of
51       option, facility, and priority.
52
53   option
54       The option argument to openlog() is an OR of any of these:
55
56       LOG_CONS       Write directly to system console if there  is  an  error
57                      while sending to system logger.
58
59       LOG_NDELAY     Open  the  connection immediately (normally, the connec‐
60                      tion is opened when the first message is logged).
61
62       LOG_NOWAIT     Don't wait for child processes that may have  been  cre‐
63                      ated while logging the message.  (The GNU C library does
64                      not create a child process, so this option has no effect
65                      on Linux.)
66
67       LOG_ODELAY     The converse of LOG_NDELAY; opening of the connection is
68                      delayed until syslog() is called.  (This is the default,
69                      and need not be specified.)
70
71       LOG_PERROR     (Not  in POSIX.1-2001 or POSIX.1-2008.)  Print to stderr
72                      as well.
73
74       LOG_PID        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       security/authorization messages
82
83       LOG_AUTHPRIV   security/authorization messages (private)
84
85       LOG_CRON       clock daemon (cron and at)
86
87       LOG_DAEMON     system daemons without separate facility value
88
89       LOG_FTP        ftp daemon
90
91       LOG_KERN       kernel messages (these can't be generated from user pro‐
92                      cesses)
93
94       LOG_LOCAL0 through LOG_LOCAL7
95                      reserved for local use
96
97       LOG_LPR        line printer subsystem
98
99       LOG_MAIL       mail subsystem
100
101       LOG_NEWS       USENET news subsystem
102
103       LOG_SYSLOG     messages generated internally by syslogd(8)
104
105       LOG_USER (default)
106                      generic user-level messages
107
108       LOG_UUCP       UUCP subsystem
109
110   level
111       This  determines  the  importance  of  the message.  The levels are, in
112       order of decreasing importance:
113
114       LOG_EMERG      system is unusable
115
116       LOG_ALERT      action must be taken immediately
117
118       LOG_CRIT       critical conditions
119
120       LOG_ERR        error conditions
121
122       LOG_WARNING    warning conditions
123
124       LOG_NOTICE     normal, but significant, condition
125
126       LOG_INFO       informational message
127
128       LOG_DEBUG      debug-level message
129
130       The function setlogmask(3) can be used to restrict logging to specified
131       levels only.
132

CONFORMING TO

134       The  functions  openlog(), closelog(), and syslog() (but not vsyslog())
135       are specified in SUSv2, POSIX.1-2001, and  POSIX.1-2008.   POSIX.1-2001
136       specifies  only  the LOG_USER and LOG_LOCAL* values for facility.  How‐
137       ever, with the exception of LOG_AUTHPRIV and LOG_FTP, the other  facil‐
138       ity  values  appear  on  most  UNIX  systems.  The LOG_PERROR value for
139       option is not specified by POSIX.1-2001 or POSIX.1-2008, but is  avail‐
140       able in most versions of UNIX.
141

NOTES

143       The  argument  ident in the call of openlog() is probably stored as-is.
144       Thus, if the string  it  points  to  is  changed,  syslog()  may  start
145       prepending the changed string, and if the string it points to ceases to
146       exist, the results are undefined.  Most portable is  to  use  a  string
147       constant.
148
149       Never  pass  a string with user-supplied data as a format, use the fol‐
150       lowing instead:
151
152           syslog(priority, "%s", string);
153

SEE ALSO

155       logger(1), setlogmask(3), syslog.conf(5), syslogd(8)
156

COLOPHON

158       This page is part of release 3.53 of the Linux  man-pages  project.   A
159       description  of  the project, and information about reporting bugs, can
160       be found at http://www.kernel.org/doc/man-pages/.
161
162
163
164Linux                             2012-08-17                         SYSLOG(3)
Impressum