summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/syslog.h
blob: 748a4faecb751c3080a8692cd1e37480039c28f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef _SYSLOG_H
#define _SYSLOG_H

/** @file
 *
 * System logger
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <stdarg.h>
#include <ipxe/ansiesc.h>
#include <config/console.h>

/**
 * @defgroup syslogpri Syslog priorities
 *
 * These values are chosen to match those used in the syslog network
 * protocol (RFC 5424).
 *
 * @{
 */

/** Emergency: system is unusable */
#define LOG_EMERG 0

/** Alert: action must be taken immediately */
#define LOG_ALERT 1

/** Critical: critical conditions */
#define LOG_CRIT 2

/** Error: error conditions */
#define LOG_ERR 3

/** Warning: warning conditions */
#define LOG_WARNING 4

/** Notice: normal but significant conditions */
#define LOG_NOTICE 5

/** Informational: informational messages */
#define LOG_INFO 6

/** Debug: debug-level messages */
#define LOG_DEBUG 7

/** @} */

/** Do not log any messages */
#define LOG_NONE -1

/** Log all messages */
#define LOG_ALL LOG_DEBUG

extern void log_vprintf ( const char *fmt, va_list args );

extern void __attribute__ (( format ( printf, 1, 2 ) ))
log_printf ( const char *fmt, ... );

/** ANSI private escape sequence to set syslog priority
 *
 * @v priority		Priority
 */
#define SYSLOG_SET_PRIORITY( priority ) \
	"\033[" #priority "p"

/** ANSI private escape sequence to clear syslog priority */
#define SYSLOG_CLEAR_PRIORITY "\033[p"

/**
 * Write message to system log
 *
 * @v priority		Message priority
 * @v fmt		Format string
 * @v ...		Arguments
 */
#define vsyslog( priority, fmt, args ) do {				\
	if ( (priority) <= LOG_LEVEL ) {				\
		log_vprintf ( SYSLOG_SET_PRIORITY ( priority ) fmt	\
			      SYSLOG_CLEAR_PRIORITY, (args) );		\
	}								\
	} while ( 0 )

/**
 * Write message to system log
 *
 * @v priority		Message priority
 * @v fmt		Format string
 * @v ...		Arguments
 */
#define syslog( priority, fmt, ... ) do {				\
	if ( (priority) <= LOG_LEVEL ) {				\
		log_printf ( SYSLOG_SET_PRIORITY ( priority ) fmt	\
			     SYSLOG_CLEAR_PRIORITY, ##__VA_ARGS__ );	\
	}								\
	} while ( 0 )

#endif /* _SYSLOG_H */