The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
syslog.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file syslog.h
5 * @brief the system log: ginnOS writes each message to the kernel log
6 * (/dev/kmsg), with the name, the pid and the level before it.
7 */
8
9#include <stdarg.h>
10
11// levels
12#define LOG_EMERG 0
13#define LOG_ALERT 1
14#define LOG_CRIT 2
15#define LOG_ERR 3
16#define LOG_WARNING 4
17#define LOG_NOTICE 5
18#define LOG_INFO 6
19#define LOG_DEBUG 7
20
21// facilities (kept in the message, not used)
22#define LOG_KERN (0 << 3)
23#define LOG_USER (1 << 3)
24#define LOG_MAIL (2 << 3)
25#define LOG_DAEMON (3 << 3)
26#define LOG_AUTH (4 << 3)
27#define LOG_SYSLOG (5 << 3)
28#define LOG_LPR (6 << 3)
29#define LOG_NEWS (7 << 3)
30#define LOG_UUCP (8 << 3)
31#define LOG_CRON (9 << 3)
32#define LOG_AUTHPRIV (10 << 3)
33#define LOG_LOCAL0 (16 << 3)
34#define LOG_LOCAL1 (17 << 3)
35#define LOG_LOCAL2 (18 << 3)
36#define LOG_LOCAL3 (19 << 3)
37#define LOG_LOCAL4 (20 << 3)
38#define LOG_LOCAL5 (21 << 3)
39#define LOG_LOCAL6 (22 << 3)
40#define LOG_LOCAL7 (23 << 3)
41
42#define LOG_PRIMASK 7
43#define LOG_PRI(p) ((p) & LOG_PRIMASK)
44#define LOG_MASK(level) (1 << (level))
45#define LOG_UPTO(level) ((1 << ((level) + 1)) - 1)
46#define LOG_FACMASK 0x03f8
47#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
48#define LOG_MAKEPRI(facility, level) ((facility) | (level))
49#define LOG_NFACILITIES 24
50
51#ifdef SYSLOG_NAMES
52// the names of the levels and the facilities, for tools such as logger.
53// a program that defines SYSLOG_NAMES before this header gets a copy.
54typedef struct
55{
56 char *c_name;
57 int c_val;
58} CODE;
59
60__attribute__((unused)) static CODE prioritynames[] = {
61 {"alert", LOG_ALERT}, {"crit", LOG_CRIT}, {"debug", LOG_DEBUG},
62 {"emerg", LOG_EMERG}, {"err", LOG_ERR}, {"error", LOG_ERR},
63 {"info", LOG_INFO}, {"notice", LOG_NOTICE}, {"panic", LOG_EMERG},
64 {"warn", LOG_WARNING}, {"warning", LOG_WARNING}, {0, -1},
65};
66
67__attribute__((unused)) static CODE facilitynames[] = {
68 {"auth", LOG_AUTH}, {"authpriv", LOG_AUTHPRIV}, {"cron", LOG_CRON},
69 {"daemon", LOG_DAEMON}, {"kern", LOG_KERN}, {"lpr", LOG_LPR},
70 {"mail", LOG_MAIL}, {"news", LOG_NEWS}, {"security", LOG_AUTH},
71 {"syslog", LOG_SYSLOG}, {"user", LOG_USER}, {"uucp", LOG_UUCP},
72 {"local0", LOG_LOCAL0}, {"local1", LOG_LOCAL1}, {"local2", LOG_LOCAL2},
73 {"local3", LOG_LOCAL3}, {"local4", LOG_LOCAL4}, {"local5", LOG_LOCAL5},
74 {"local6", LOG_LOCAL6}, {"local7", LOG_LOCAL7}, {0, -1},
75};
76#endif
77
78// openlog options
79#define LOG_PID 0x01 // the pid after the name
80#define LOG_CONS 0x02 // to the console too when the log cannot be written
81#define LOG_ODELAY 0x04
82#define LOG_NDELAY 0x08
83#define LOG_NOWAIT 0x10
84#define LOG_PERROR 0x20 // to stderr too
85
86void openlog(const char *ident, int options, int facility);
87void syslog(int priority, const char *format, ...) __attribute__((format(printf, 2, 3)));
88void vsyslog(int priority, const char *format, va_list args);
89void closelog(void);
90/** the levels to write (LOG_MASK bits); returns the old mask (0: no change) */
91int setlogmask(int mask);
variable argument lists (the compiler's builtins).
__builtin_va_list va_list
variadic arguments, from the compiler's builtins.
Definition stdarg.h:8
int printf(const char *fmt,...) __attribute__((format(printf
formatted output.
ELF32 file header.
Definition elf.h:51
#define LOG_ALERT
Definition syslog.h:13
#define LOG_MAIL
Definition syslog.h:24
#define LOG_AUTH
Definition syslog.h:26
#define LOG_LOCAL0
Definition syslog.h:33
#define LOG_CRON
Definition syslog.h:31
#define LOG_KERN
Definition syslog.h:22
#define LOG_LOCAL2
Definition syslog.h:35
#define LOG_LPR
Definition syslog.h:28
#define LOG_EMERG
Definition syslog.h:12
#define LOG_AUTHPRIV
Definition syslog.h:32
#define LOG_DEBUG
Definition syslog.h:19
#define LOG_LOCAL6
Definition syslog.h:39
int setlogmask(int mask)
the levels to write (LOG_MASK bits); returns the old mask (0: no change)
#define LOG_LOCAL4
Definition syslog.h:37
#define LOG_ERR
Definition syslog.h:15
#define LOG_DAEMON
Definition syslog.h:25
#define LOG_CRIT
Definition syslog.h:14
#define LOG_SYSLOG
Definition syslog.h:27
#define LOG_UUCP
Definition syslog.h:30
void openlog(const char *ident, int options, int facility)
#define LOG_LOCAL5
Definition syslog.h:38
#define LOG_USER
Definition syslog.h:23
#define LOG_NOTICE
Definition syslog.h:17
#define LOG_LOCAL3
Definition syslog.h:36
#define LOG_WARNING
Definition syslog.h:16
void closelog(void)
#define LOG_LOCAL1
Definition syslog.h:34
#define LOG_LOCAL7
Definition syslog.h:40
#define LOG_NEWS
Definition syslog.h:29
#define LOG_INFO
Definition syslog.h:18
void syslog(int priority, const char *format,...) __attribute__((format(printf
void void vsyslog(int priority, const char *format, va_list args)