1*48352Scael.\" Copyright (c) 1985, 1991 The Regents of the University of California. 236444Sbostic.\" All rights reserved. 320470Smckusick.\" 443571Strent.\" %sccs.include.redist.man% 520470Smckusick.\" 6*48352Scael.\" @(#)syslog.3 6.17 (Berkeley) 04/19/91 736444Sbostic.\" 8*48352Scael.Dd 9*48352Scael.Dt SYSLOG 3 10*48352Scael.Os BSD 4.2 11*48352Scael.Sh NAME 12*48352Scael.Nm syslog , 13*48352Scael.Nm vsyslog , 14*48352Scael.Nm openlog , 15*48352Scael.Nm closelog , 16*48352Scael.Nm setlogmask 17*48352Scael.Nd control system log 18*48352Scael.Sh SYNOPSIS 19*48352Scael.Fd #include <syslog.h> 20*48352Scael.Fd #include <varargs.h> 21*48352Scael.Ft void 22*48352Scael.Fn syslog "int priority" "const char *message" "..." 23*48352Scael.Ft void 24*48352Scael.Fn vsyslog "int priority" "const char *message" "va_list args" 25*48352Scael.Ft void 26*48352Scael.Fn openlog "const char *ident" "int logopt" "int facility" 27*48352Scael.Ft void 28*48352Scael.Fn closelog void 29*48352Scael.Ft int 30*48352Scael.Fn setlogmask "int maskpri" 31*48352Scael.Sh DESCRIPTION 32*48352ScaelThe 33*48352Scael.Fn syslog 34*48352Scaelfunction 3545265Sbosticwrites 36*48352Scael.Fa message 3745265Sbosticto the system message logger. 38*48352ScaelThe message is then written to the system console, log files, 39*48352Scaellogged-in users, or forwarded to other machines as appropriate. (See 40*48352Scael.Xr syslogd 8 . ) 41*48352Scael.Pp 4245265SbosticThe message is identical to a 43*48352Scael.Xr printf 3 44*48352Scaelformat string, except that 45*48352Scael.Ql %m 46*48352Scaelis replaced by the current error 47*48352Scaelmessage. (As denoted by the global variable 48*48352Scael.Va errno ; 4945265Sbosticsee 50*48352Scael.Xr strerror 3 . ) 5145265SbosticA trailing newline is added if none is present. 52*48352Scael.Pp 53*48352ScaelThe 54*48352Scael.Fn vsyslog 55*48352Scaelfunction 5645265Sbosticis an alternate form in which the arguments have already been captured 5738722Sbosticusing the variable-length argument facilities of 58*48352Scael.Xr varargs 3 . 59*48352Scael.Pp 6045265SbosticThe message is tagged with 61*48352Scael.Fa priority . 6224867SericPriorities are encoded as a 63*48352Scael.Fa facility 6424867Sericand a 65*48352Scael.Em level . 6624867SericThe facility describes the part of the system 6724867Sericgenerating the message. 6845265SbosticThe level is selected from the following 69*48352Scael.Em ordered 7045265Sbostic(high to low) list: 71*48352Scael.Bl -tag -width LOG_AUTHPRIV 72*48352Scael.It Dv LOG_EMERG 7345265SbosticA panic condition. 7445265SbosticThis is normally broadcast to all users. 75*48352Scael.It Dv LOG_ALERT 7645265SbosticA condition that should be corrected immediately, such as a corrupted 7745265Sbosticsystem database. 78*48352Scael.It Dv LOG_CRIT 7945265SbosticCritical conditions, e.g., hard device errors. 80*48352Scael.It Dv LOG_ERR 8124867SericErrors. 82*48352Scael.It Dv LOG_WARNING 8345265SbosticWarning messages. 84*48352Scael.It Dv LOG_NOTICE 8524867SericConditions that are not error conditions, 8624867Sericbut should possibly be handled specially. 87*48352Scael.It Dv LOG_INFO 8845265SbosticInformational messages. 89*48352Scael.It Dv LOG_DEBUG 9045265SbosticMessages that contain information 9145265Sbosticnormally of use only when debugging a program. 92*48352Scael.El 93*48352Scael.Pp 94*48352ScaelThe 95*48352Scael.Fn openlog 96*48352Scaelfunction 9745265Sbosticprovides for more specialized processing of the messages sent 9845265Sbosticby 99*48352Scael.Fn syslog 10045265Sbosticand 101*48352Scael.Fn vsyslog . 10220471SmckusickThe parameter 103*48352Scael.Fa ident 10445265Sbosticis a string that will be prepended to every message. 105*48352ScaelThe 106*48352Scael.Fa logopt 107*48352Scaelargument 10845265Sbosticis a bit field specifying logging options, which is formed by 109*48352Scael.Tn OR Ns 'ing 11045265Sbosticone or more of the following values: 111*48352Scael.Bl -tag -width LOG_AUTHPRIV 112*48352Scael.It Dv LOG_CONS 11345265SbosticIf 114*48352Scael.Fn syslog 11545265Sbosticcannot pass the message to 116*48352Scael.Xr syslogd 117*48352Scaelit will attempt to write the message to the console 118*48352Scael.Pq Dq Pa /dev/console. 119*48352Scael.It Dv LOG_NDELAY 12028214SkarelsOpen the connection to 121*48352Scael.Xr syslogd 12225188Sericimmediately. 12345265SbosticNormally the open is delayed until the first message is logged. 12445265SbosticUseful for programs that need to manage the order in which file 12545265Sbosticdescriptors are allocated. 126*48352Scael.It Dv LOG_PERROR 12745265SbosticWrite the message to standard error output as well to the system log. 128*48352Scael.It Dv LOG_PID 12945265SbosticLog the process id with each message: useful for identifying 13045265Sbosticinstantiations of daemons. 131*48352Scael.El 132*48352Scael.Pp 13320471SmckusickThe 134*48352Scael.Fa facility 13528214Skarelsparameter encodes a default facility to be assigned to all messages 13624867Sericthat do not have an explicit facility encoded: 137*48352Scael.Bl -tag -width LOG_AUTHPRIV 138*48352Scael.It Dv LOG_AUTH 13938722SbosticThe authorization system: 140*48352Scael.Xr login 1 , 141*48352Scael.Xr su 1 , 142*48352Scael.Xr getty 8 , 14338722Sbosticetc. 144*48352Scael.It Dv LOG_AUTHPRIV 145*48352ScaelThe same as 146*48352Scael.Dv LOG_AUTH , 147*48352Scaelbut logged to a file readable only by 14845265Sbosticselected individuals. 149*48352Scael.It Dv LOG_CRON 15038722SbosticThe clock daemon. 151*48352Scael.It Dv LOG_DAEMON 15224867SericSystem daemons, such as 153*48352Scael.Xr ftpd 8 , 154*48352Scael.Xr routed 8 , 15545265Sbosticetc., that are not provided for explicitly by other facilities. 156*48352Scael.It Dv LOG_KERN 15738722SbosticMessages generated by the kernel. 15838722SbosticThese cannot be generated by any user processes. 159*48352Scael.It Dv LOG_LPR 16025493SericThe line printer spooling system: 161*48352Scael.Xr lpr 1 , 162*48352Scael.Xr lpc 8 , 163*48352Scael.Xr lpd 8 , 16425493Sericetc. 165*48352Scael.It Dv LOG_MAIL 16638722SbosticThe mail system. 167*48352Scael.It Dv LOG_NEWS 16837246SbosticThe network news system. 169*48352Scael.It Dv LOG_SYSLOG 17038722SbosticMessages generated internally by 171*48352Scael.Xr syslogd 8 . 172*48352Scael.It Dv LOG_USER 17338722SbosticMessages generated by random user processes. 17438722SbosticThis is the default facility identifier if none is specified. 175*48352Scael.It Dv LOG_UUCP 17637246SbosticThe uucp system. 177*48352Scael.It Dv LOG_LOCAL0 17824867SericReserved for local use. 179*48352ScaelSimilarly for 180*48352Scael.Dv LOG_LOCAL1 181*48352Scaelthrough 182*48352Scael.Dv LOG_LOCAL7 . 183*48352Scael.El 184*48352Scael.Pp 185*48352ScaelThe 186*48352Scael.Fn closelog 187*48352Scaelfunction 18820470Smckusickcan be used to close the log file. 189*48352Scael.Pp 190*48352ScaelThe 191*48352Scael.Fn setlogmask 192*48352Scaelfunction 19320471Smckusicksets the log priority mask to 194*48352Scael.Fa maskpri 19520471Smckusickand returns the previous mask. 19624867SericCalls to 197*48352Scael.Fn syslog 19828214Skarelswith a priority not set in 199*48352Scael.Fa maskpri 20024867Sericare rejected. 20128214SkarelsThe mask for an individual priority 202*48352Scael.Fa pri 203*48352Scaelis calculated by the macro 204*48352Scael.Fn LOG_MASK pri ; 20528214Skarelsthe mask for all priorities up to and including 206*48352Scael.Fa toppri 207*48352Scaelis given by the macro 208*48352Scael.Fn LOG_UPTO toppri ; . 20924867SericThe default allows all priorities to be logged. 210*48352Scael.Sh RETURN VALUES 211*48352ScaelThe routines 212*48352Scael.Fn closelog , 213*48352Scael.Fn openlog , 214*48352Scael.Fn syslog 215*48352Scaeland 216*48352Scael.Fn vsyslog 217*48352Scaelreturn no value. 218*48352Scael.Pp 219*48352ScaelThe routine 220*48352Scael.Fn setlogmask 221*48352Scaelalways returns the previous log mask level. 222*48352Scael.Sh EXAMPLES 223*48352Scael.Bd -literal -offset indent -compact 22424867Sericsyslog(LOG_ALERT, "who: internal error 23"); 22520470Smckusick 22624867Sericopenlog("ftpd", LOG_PID, LOG_DAEMON); 22728214Skarelssetlogmask(LOG_UPTO(LOG_ERR)); 22820470Smckusicksyslog(LOG_INFO, "Connection from host %d", CallingHost); 22924867Seric 23024867Sericsyslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); 231*48352Scael.Ed 232*48352Scael.Sh SEE ALSO 233*48352Scael.Xr logger 1 , 234*48352Scael.Xr syslogd 8 235*48352Scael.Sh HISTORY 236*48352ScaelThese 237*48352Scaelfunctions appeared in 238*48352Scael.Bx 4.2 . 239