1SYSLOG(3) Library Functions Manual SYSLOG(3)
2
3
4
6 syslog , vsyslog , openlog , closelog , setlogmask - control system log
7
9 #include <syslog.h>
10 #include <varargs.h>
11
12 void syslog(priority, message, ...);
13 int priority;
14 char *message;
15
16 void vsyslog(priority, message, args);
17 int priority;
18 char *message;
19 va_list args;
20
21 void openlog(ident, logopt, facility);
22 char *ident;
23 int logopt;
24 int facility;
25
26 void closelog();
27
28 int setlogmask(maskpri);
29 int maskpri;
30
32 The syslog() function writes message to the system message logger. The
33 message is then written to the system console, log files, logged-in
34 users, or forwarded to other machines as appropriate. (See syslogd(8)).
35
36 The message is identical to a printf(3) format string, except that %m
37 is replaced by the current error message as denoted by the global vari‐
38 able errno. See strerror(3)). A trailing newline is added if none is
39 present.
40
41 The vsyslog() function is an alternate form in which the arguments have
42 already been captured using the variable-length argument facilities of
43 varargs(3).
44
45 The message is tagged with priority. Priorities are encoded as a
46 facility and a level. The facility describes the part of the system
47 generating the message. The level is selected from the following
48 ordered (high to low) list:
49
50 LOG_EMERG A panic condition. This is normally broadcast to all
51 users.
52
53 LOG_ALERT A condition that should be corrected immediately, such
54 as a corrupted system database.
55
56 LOG_CRIT Critical conditions, e.g., hard device errors.
57
58 LOG_ERR Errors.
59
60 LOG_WARNING Warning messages.
61
62 LOG_NOTICE Conditions that are not error conditions, but should
63 possibly be handled specially.
64
65 LOG_INFO Informational messages.
66
67 LOG_DEBUG Messages that contain information normally of use only
68 when debugging a program.
69
70 The openlog() function provides for more specialized processing of the
71 messages sent by syslog() and vsyslog(). The parameter ident is a
72 string that will be prepended to every message. The logopt argument is
73 a bit field specifying logging options, which is formed by OR'ing one
74 or more of the following values:
75
76 LOG_CONS If syslog cannot pass the message to syslogd it will
77 attempt to write the message to the console (/dev/con‐
78 sole).
79
80 LOG_NDELAY Open the connection to syslogd immediately. Normally
81 the open is delayed until the first message is logged.
82 Useful for programs that need to manage the order in
83 which file descriptors are allocated.
84
85 LOG_PERROR Write the message to standard error output as well to
86 the system log.
87
88 LOG_PID Log the process id with each message: useful for identi‐
89 fying instantiations of daemons.
90
91 The facility parameter encodes a default facility to be assigned to all
92 messages that do not have an explicit facility encoded:
93
94 LOG_AUTH The authorization system: login(1), su(1), getty(8),
95 etc.
96
97 LOG_AUTHPRIV The same as LOG_AUTH , but logged to a file readable
98 only by selected individuals.
99
100 LOG_CRON The clock daemon.
101
102 LOG_DAEMON System daemons, such as routed(8), that are not provided
103 for explicitly by other facilities.
104
105 LOG_KERN Messages generated by the kernel. These cannot be gen‐
106 erated by any user processes.
107
108 LOG_LPR The line printer spooling system: lpr(1), lpc(8),
109 lpd(8), etc.
110
111 LOG_MAIL The mail system.
112
113 LOG_NEWS The network news system.
114
115 LOG_SYSLOG Messages generated internally by syslogd(8).
116
117 LOG_USER Messages generated by random user processes. This is
118 the default facility identifier if none is specified.
119
120 LOG_UUCP The uucp system.
121
122 LOG_LOCAL0 Reserved for local use. Similarly for LOG_LOCAL1
123 through LOG_LOCAL7.
124
125 The closelog function can be used to close the log file.
126
127 The setlogmask function sets the log priority mask to maskpri and
128 returns the previous mask. Calls to syslog with a priority not set in
129 maskpri are rejected. The mask for an individual priority pri is cal‐
130 culated by the macro LOG_MASK(pri). The mask for all priorities up to
131 and including toppri is given by the macro LOG_UPTO(toppri). The
132 default allows all priorities to be logged.
133
135 The routines closelog(), openlog(), syslog() and vsyslog() return no
136 value.
137
138 The routine setlogmask() always returns the previous log mask level.
139
141 syslog(LOG_ALERT, "who: internal error 23");
142
143 openlog("ftpd", LOG_PID, LOG_DAEMON); setlog‐
144 mask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host
145 %d", CallingHost);
146
147 syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
148
150 logger(1), syslogd(8)
151
153 Under 2.11BSD the logfile /usr/adm/messages is used if a non networking
154 kernel has been booted. That file must be publically writeable in this
155 case.
156
158 These functions appeared in 4.2BSD.
159
160
161
1624.2 Berkeley Distribution April 1, 1995 SYSLOG(3)