xref: /csrg-svn/lib/libc/gen/syslog.3 (revision 61111)
1*61111Sbostic.\" Copyright (c) 1985, 1991, 1993
2*61111Sbostic.\"	The Regents of the University of California.  All rights reserved.
320470Smckusick.\"
443571Strent.\" %sccs.include.redist.man%
520470Smckusick.\"
6*61111Sbostic.\"     @(#)syslog.3	8.1 (Berkeley) 06/04/93
736444Sbostic.\"
848352Scael.Dd
948352Scael.Dt SYSLOG 3
1048352Scael.Os BSD 4.2
1148352Scael.Sh NAME
1248352Scael.Nm syslog ,
1348352Scael.Nm vsyslog ,
1448352Scael.Nm openlog ,
1548352Scael.Nm closelog ,
1648352Scael.Nm setlogmask
1748352Scael.Nd control system log
1848352Scael.Sh SYNOPSIS
1948352Scael.Fd #include <syslog.h>
2048352Scael.Fd #include <varargs.h>
2148352Scael.Ft void
2248352Scael.Fn syslog "int priority" "const char *message" "..."
2348352Scael.Ft void
2448352Scael.Fn vsyslog "int priority" "const char *message" "va_list args"
2548352Scael.Ft void
2648352Scael.Fn openlog "const char *ident" "int logopt" "int facility"
2748352Scael.Ft void
2848352Scael.Fn closelog void
2948352Scael.Ft int
3048352Scael.Fn setlogmask "int maskpri"
3148352Scael.Sh DESCRIPTION
3248352ScaelThe
3348352Scael.Fn syslog
3448352Scaelfunction
3545265Sbosticwrites
3648352Scael.Fa message
3745265Sbosticto the system message logger.
3848352ScaelThe message is then written to the system console, log files,
3948352Scaellogged-in users, or forwarded to other machines as appropriate. (See
4048352Scael.Xr syslogd 8 . )
4148352Scael.Pp
4245265SbosticThe message is identical to a
4348352Scael.Xr printf 3
4448352Scaelformat string, except that
4548352Scael.Ql %m
4648352Scaelis replaced by the current error
4748352Scaelmessage. (As denoted by the global variable
4848352Scael.Va errno ;
4945265Sbosticsee
5048352Scael.Xr strerror 3 . )
5145265SbosticA trailing newline is added if none is present.
5248352Scael.Pp
5348352ScaelThe
5448352Scael.Fn vsyslog
5548352Scaelfunction
5645265Sbosticis an alternate form in which the arguments have already been captured
5738722Sbosticusing the variable-length argument facilities of
5848352Scael.Xr varargs 3 .
5948352Scael.Pp
6045265SbosticThe message is tagged with
6148352Scael.Fa priority .
6224867SericPriorities are encoded as a
6348352Scael.Fa facility
6424867Sericand a
6548352Scael.Em level .
6624867SericThe facility describes the part of the system
6724867Sericgenerating the message.
6845265SbosticThe level is selected from the following
6948352Scael.Em ordered
7045265Sbostic(high to low) list:
7148352Scael.Bl -tag -width LOG_AUTHPRIV
7248352Scael.It Dv LOG_EMERG
7345265SbosticA panic condition.
7445265SbosticThis is normally broadcast to all users.
7548352Scael.It Dv LOG_ALERT
7645265SbosticA condition that should be corrected immediately, such as a corrupted
7745265Sbosticsystem database.
7848352Scael.It Dv LOG_CRIT
7945265SbosticCritical conditions, e.g., hard device errors.
8048352Scael.It Dv LOG_ERR
8124867SericErrors.
8248352Scael.It Dv LOG_WARNING
8345265SbosticWarning messages.
8448352Scael.It Dv LOG_NOTICE
8524867SericConditions that are not error conditions,
8624867Sericbut should possibly be handled specially.
8748352Scael.It Dv LOG_INFO
8845265SbosticInformational messages.
8948352Scael.It Dv LOG_DEBUG
9045265SbosticMessages that contain information
9145265Sbosticnormally of use only when debugging a program.
9248352Scael.El
9348352Scael.Pp
9448352ScaelThe
9548352Scael.Fn openlog
9648352Scaelfunction
9745265Sbosticprovides for more specialized processing of the messages sent
9845265Sbosticby
9948352Scael.Fn syslog
10045265Sbosticand
10148352Scael.Fn vsyslog .
10220471SmckusickThe parameter
10348352Scael.Fa ident
10445265Sbosticis a string that will be prepended to every message.
10548352ScaelThe
10648352Scael.Fa logopt
10748352Scaelargument
10845265Sbosticis a bit field specifying logging options, which is formed by
10948352Scael.Tn OR Ns 'ing
11045265Sbosticone or more of the following values:
11148352Scael.Bl -tag -width LOG_AUTHPRIV
11248352Scael.It Dv LOG_CONS
11345265SbosticIf
11448352Scael.Fn syslog
11545265Sbosticcannot pass the message to
11648352Scael.Xr syslogd
11748352Scaelit will attempt to write the message to the console
11848352Scael.Pq Dq Pa /dev/console.
11948352Scael.It Dv LOG_NDELAY
12028214SkarelsOpen the connection to
12148352Scael.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.
12648352Scael.It Dv LOG_PERROR
12745265SbosticWrite the message to standard error output as well to the system log.
12848352Scael.It Dv LOG_PID
12945265SbosticLog the process id with each message: useful for identifying
13045265Sbosticinstantiations of daemons.
13148352Scael.El
13248352Scael.Pp
13320471SmckusickThe
13448352Scael.Fa facility
13528214Skarelsparameter encodes a default facility to be assigned to all messages
13624867Sericthat do not have an explicit facility encoded:
13748352Scael.Bl -tag -width LOG_AUTHPRIV
13848352Scael.It Dv LOG_AUTH
13938722SbosticThe authorization system:
14048352Scael.Xr login 1 ,
14148352Scael.Xr su 1 ,
14248352Scael.Xr getty 8 ,
14338722Sbosticetc.
14448352Scael.It Dv LOG_AUTHPRIV
14548352ScaelThe same as
14648352Scael.Dv LOG_AUTH ,
14748352Scaelbut logged to a file readable only by
14845265Sbosticselected individuals.
14948352Scael.It Dv LOG_CRON
15038722SbosticThe clock daemon.
15148352Scael.It Dv LOG_DAEMON
15224867SericSystem daemons, such as
15348352Scael.Xr routed 8 ,
15455086Sbosticthat are not provided for explicitly by other facilities.
15548352Scael.It Dv LOG_KERN
15638722SbosticMessages generated by the kernel.
15738722SbosticThese cannot be generated by any user processes.
15848352Scael.It Dv LOG_LPR
15925493SericThe line printer spooling system:
16048352Scael.Xr lpr 1 ,
16148352Scael.Xr lpc 8 ,
16248352Scael.Xr lpd 8 ,
16325493Sericetc.
16448352Scael.It Dv LOG_MAIL
16538722SbosticThe mail system.
16648352Scael.It Dv LOG_NEWS
16737246SbosticThe network news system.
16848352Scael.It Dv LOG_SYSLOG
16938722SbosticMessages generated internally by
17048352Scael.Xr syslogd 8 .
17148352Scael.It Dv LOG_USER
17238722SbosticMessages generated by random user processes.
17338722SbosticThis is the default facility identifier if none is specified.
17448352Scael.It Dv LOG_UUCP
17537246SbosticThe uucp system.
17648352Scael.It Dv LOG_LOCAL0
17724867SericReserved for local use.
17848352ScaelSimilarly for
17948352Scael.Dv LOG_LOCAL1
18048352Scaelthrough
18148352Scael.Dv LOG_LOCAL7 .
18248352Scael.El
18348352Scael.Pp
18448352ScaelThe
18548352Scael.Fn closelog
18648352Scaelfunction
18720470Smckusickcan be used to close the log file.
18848352Scael.Pp
18948352ScaelThe
19048352Scael.Fn setlogmask
19148352Scaelfunction
19220471Smckusicksets the log priority mask to
19348352Scael.Fa maskpri
19420471Smckusickand returns the previous mask.
19524867SericCalls to
19648352Scael.Fn syslog
19728214Skarelswith a priority not set in
19848352Scael.Fa maskpri
19924867Sericare rejected.
20028214SkarelsThe mask for an individual priority
20148352Scael.Fa pri
20248352Scaelis calculated by the macro
20348352Scael.Fn LOG_MASK pri ;
20428214Skarelsthe mask for all priorities up to and including
20548352Scael.Fa toppri
20648352Scaelis given by the macro
20748352Scael.Fn LOG_UPTO toppri ; .
20824867SericThe default allows all priorities to be logged.
20948352Scael.Sh RETURN VALUES
21048352ScaelThe routines
21148352Scael.Fn closelog ,
21248352Scael.Fn openlog ,
21348352Scael.Fn syslog
21448352Scaeland
21548352Scael.Fn vsyslog
21648352Scaelreturn no value.
21748352Scael.Pp
21848352ScaelThe routine
21948352Scael.Fn setlogmask
22048352Scaelalways returns the previous log mask level.
22148352Scael.Sh EXAMPLES
22248352Scael.Bd -literal -offset indent -compact
22324867Sericsyslog(LOG_ALERT, "who: internal error 23");
22420470Smckusick
22524867Sericopenlog("ftpd", LOG_PID, LOG_DAEMON);
22628214Skarelssetlogmask(LOG_UPTO(LOG_ERR));
22720470Smckusicksyslog(LOG_INFO, "Connection from host %d", CallingHost);
22824867Seric
22924867Sericsyslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
23048352Scael.Ed
23148352Scael.Sh SEE ALSO
23248352Scael.Xr logger 1 ,
23348352Scael.Xr syslogd 8
23448352Scael.Sh HISTORY
23548352ScaelThese
23648352Scaelfunctions appeared in
23748352Scael.Bx 4.2 .
238