173 lines
6.9 KiB
C
173 lines
6.9 KiB
C
#ifndef VLIBC_SYSLOG_H
|
|
#define VLIBC_SYSLOG_H
|
|
|
|
/*
|
|
* vlibc — <syslog.h>.
|
|
*
|
|
* The syslog(3) logging interface, writing BSD-syslog datagrams to the
|
|
* /dev/log socket (see src/misc/syslog.c for the wire details). syslog is
|
|
* NOT POSIX.1-2008 base — it is XSI [CX] (and historical BSD), so this
|
|
* ENTIRE header is gated at `VLIBC_LEVEL >= 2`: at level 1 (onlyposix) it is
|
|
* empty, exactly like <strings.h>.
|
|
*
|
|
* The interface has three parts:
|
|
*
|
|
* - facilities and severities, plus the option flags of openlog. The
|
|
* facility constants carry the classic BSD values, which are the Linux
|
|
* wire ABI for /dev/log: facility = code << 3, severity = 0..7, and the
|
|
* datagram's numeric priority is facility | severity. The facility code
|
|
* is passed on the wire, so these numbers must match what syslogd
|
|
* expects and are therefore kernel-ABI facts, not invented values;
|
|
*
|
|
* - LOG_MASK / LOG_UPTO, the two macros that build the mask argument of
|
|
* setlogmask (LOG_MASK is POSIX; LOG_UPTO is the classic convenience
|
|
* form both musl and glibc provide);
|
|
*
|
|
* - openlog / syslog / closelog / setlogmask and the vsyslog entry point
|
|
* the standard requires syslog to be implemented in terms of. None of
|
|
* them carries an intent attribute: every one reads and writes global
|
|
* logging state and performs I/O, so const/pure would be unsound.
|
|
*
|
|
* %m handling: inside the syslog format string, "%m" is replaced by the
|
|
* strerror(errno) text (a syslog-specific feature, implemented in syslog.c —
|
|
* NOT a printf conversion). All other conversions are the standard ones,
|
|
* handled by the library's own vsnprintf.
|
|
*
|
|
* This header includes <vlibc/features.h> itself, so the gate below always
|
|
* sees the configured VLIBC_LEVEL even when the caller included no vlibc
|
|
* header first, and <stdarg.h> for va_list.
|
|
*/
|
|
|
|
#include <vlibc/features.h>
|
|
|
|
#if VLIBC_LEVEL_GE(2)
|
|
|
|
#include <stdarg.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* ---- openlog option flags (bit mask) ---- */
|
|
|
|
#define LOG_PID 0x01 /* include the calling process' PID in each message */
|
|
#define LOG_CONS 0x02 /* on send failure, write the message to the console */
|
|
#define LOG_ODELAY 0x04 /* delay opening the /dev/log socket until first use */
|
|
#define LOG_NDELAY 0x08 /* open the /dev/log socket immediately in openlog */
|
|
#define LOG_NOWAIT 0x10 /* do not wait for child processes (accepted, unused) */
|
|
#define LOG_PERROR 0x20 /* also write each message to standard error */
|
|
|
|
/* ---- facility codes (code << 3; the wire value of the datagram) ---- */
|
|
|
|
#define LOG_KERN 0 /* kernel messages */
|
|
#define LOG_USER (1 << 3) /* random user-level messages */
|
|
#define LOG_MAIL (2 << 3) /* mail system */
|
|
#define LOG_DAEMON (3 << 3) /* system daemons */
|
|
#define LOG_AUTH (4 << 3) /* security/authorization messages */
|
|
#define LOG_LPR (6 << 3) /* line printer subsystem */
|
|
#define LOG_NEWS (7 << 3) /* network news subsystem */
|
|
#define LOG_UUCP (8 << 3) /* UUCP subsystem */
|
|
#define LOG_CRON (9 << 3) /* clock daemon */
|
|
#define LOG_LOCAL0 (16 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL1 (17 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL2 (18 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL3 (19 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL4 (20 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL5 (21 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL6 (22 << 3) /* reserved for local use */
|
|
#define LOG_LOCAL7 (23 << 3) /* reserved for local use */
|
|
|
|
/* ---- severities (the low three bits of the priority value) ---- */
|
|
|
|
#define LOG_EMERG 0 /* system is unusable */
|
|
#define LOG_ALERT 1 /* action must be taken immediately */
|
|
#define LOG_CRIT 2 /* critical conditions */
|
|
#define LOG_ERR 3 /* error conditions */
|
|
#define LOG_WARNING 4 /* warning conditions */
|
|
#define LOG_NOTICE 5 /* normal but significant condition */
|
|
#define LOG_INFO 6 /* informational */
|
|
#define LOG_DEBUG 7 /* debug-level messages */
|
|
|
|
/* Bit field holding the facility part (bits 3..9) of a priority value. */
|
|
#define LOG_FACMASK 0x03f8
|
|
|
|
/* Bit field holding the severity part (bits 0..2) of a priority value. */
|
|
#define LOG_PRIMASK 0x07
|
|
|
|
/* A mask with exactly pri's bit set (pri is a LOG_* severity, 0..7). */
|
|
#define LOG_MASK(pri) (1 << (pri))
|
|
|
|
/* A mask with every severity from LOG_EMERG through pri included. */
|
|
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)
|
|
|
|
/*
|
|
* Open a connection to the system logger. ident, when non-NULL, is copied
|
|
* (a caller-owned pointer is not retained) and prefixes every message; a
|
|
* NULL ident logs messages with no tag. option ORs in the LOG_* option
|
|
* flags; facility is one of the LOG_* facility constants and is used for
|
|
* messages whose priority carries no facility of its own. With LOG_NDELAY
|
|
* the /dev/log socket is opened here; otherwise (and by default) it is
|
|
* opened lazily on the first syslog call, and a failure to open it is
|
|
* silent. Prior state — the mask from setlogmask and the default facility
|
|
* LOG_USER — persists.
|
|
*
|
|
* I/O and global state: no intent attribute.
|
|
*/
|
|
void
|
|
openlog(const char *ident, int option, int facility);
|
|
|
|
/*
|
|
* Log a message: build "<facility|severity>ident[pid]: message" and send it
|
|
* as one datagram to /dev/log, subject to the setlogmask mask. severity is
|
|
* the low three bits of priority; a facility encoded in priority overrides
|
|
* the openlog facility, and an out-of-range (high-bit) facility is ignored,
|
|
* falling back to the openlog facility. The format string is the printf
|
|
* family's, with "%m" additionally meaning the strerror(errno) text. When
|
|
* LOG_PERROR was passed to openlog the composed line also goes to standard
|
|
* error; when the send fails and LOG_CONS was passed, it goes to the console
|
|
* instead. A failed open or send never terminates the process.
|
|
*
|
|
* I/O and global state: no intent attribute.
|
|
*/
|
|
void
|
|
syslog(int priority, const char *format, ...);
|
|
|
|
/*
|
|
* Close the connection to the system logger: close the /dev/log socket if
|
|
* one is open, and clear the ident and option state installed by openlog
|
|
* (the facility and mask are retained). A later syslog reopens the socket
|
|
* lazily.
|
|
*
|
|
* I/O and global state: no intent attribute.
|
|
*/
|
|
void
|
|
closelog(void);
|
|
|
|
/*
|
|
* The engine behind syslog: identical semantics, taking a va_list instead
|
|
* of the variadic tail. Each message is formatted exactly once (through
|
|
* vsnprintf into an internal buffer) before any send, so LOG_PERROR and the
|
|
* datagram always carry the same text.
|
|
*
|
|
* I/O and global state: no intent attribute.
|
|
*/
|
|
void
|
|
vsyslog(int priority, const char *format, va_list ap);
|
|
|
|
/*
|
|
* Set the process' log priority mask to maskpri — a bit per severity where
|
|
* bit LOG_MASK(severity) set means "log this severity" — and return the
|
|
* previous mask. A mask of 0 suppresses every message. The mask applies to
|
|
* the severity only: facility is never filtered.
|
|
*/
|
|
int
|
|
setlogmask(int maskpri);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* VLIBC_LEVEL_GE(2) */
|
|
|
|
#endif /* VLIBC_SYSLOG_H */
|