iPXE
syslog.h
Go to the documentation of this file.
1 #ifndef _SYSLOG_H
2 #define _SYSLOG_H
3 
4 /** @file
5  *
6  * System logger
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdarg.h>
13 #include <ipxe/ansiesc.h>
14 #include <config/console.h>
15 
16 /**
17  * @defgroup syslogpri Syslog priorities
18  *
19  * These values are chosen to match those used in the syslog network
20  * protocol (RFC 5424).
21  *
22  * @{
23  */
24 
25 /** Emergency: system is unusable */
26 #define LOG_EMERG 0
27 
28 /** Alert: action must be taken immediately */
29 #define LOG_ALERT 1
30 
31 /** Critical: critical conditions */
32 #define LOG_CRIT 2
33 
34 /** Error: error conditions */
35 #define LOG_ERR 3
36 
37 /** Warning: warning conditions */
38 #define LOG_WARNING 4
39 
40 /** Notice: normal but significant conditions */
41 #define LOG_NOTICE 5
42 
43 /** Informational: informational messages */
44 #define LOG_INFO 6
45 
46 /** Debug: debug-level messages */
47 #define LOG_DEBUG 7
48 
49 /** @} */
50 
51 /** Do not log any messages */
52 #define LOG_NONE -1
53 
54 /** Log all messages */
55 #define LOG_ALL LOG_DEBUG
56 
57 extern void log_vprintf ( const char *fmt, va_list args );
58 
59 extern void __attribute__ (( format ( printf, 1, 2 ) ))
60 log_printf ( const char *fmt, ... );
61 
62 /** ANSI private escape sequence to set syslog priority
63  *
64  * @v priority Priority
65  */
66 #define SYSLOG_SET_PRIORITY( priority ) \
67  "\033[" #priority "p"
68 
69 /** ANSI private escape sequence to clear syslog priority */
70 #define SYSLOG_CLEAR_PRIORITY "\033[p"
71 
72 /**
73  * Write message to system log
74  *
75  * @v priority Message priority
76  * @v fmt Format string
77  * @v ... Arguments
78  */
79 #define vsyslog( priority, fmt, args ) do { \
80  if ( (priority) <= LOG_LEVEL ) { \
81  log_vprintf ( SYSLOG_SET_PRIORITY ( priority ) fmt \
82  SYSLOG_CLEAR_PRIORITY, (args) ); \
83  } \
84  } while ( 0 )
85 
86 /**
87  * Write message to system log
88  *
89  * @v priority Message priority
90  * @v fmt Format string
91  * @v ... Arguments
92  */
93 #define syslog( priority, fmt, ... ) do { \
94  if ( (priority) <= LOG_LEVEL ) { \
95  log_printf ( SYSLOG_SET_PRIORITY ( priority ) fmt \
96  SYSLOG_CLEAR_PRIORITY, ##__VA_ARGS__ ); \
97  } \
98  } while ( 0 )
99 
100 #endif /* _SYSLOG_H */
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
void log_printf(const char *fmt,...)
Write message to system log.
Definition: log.c:61
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void log_vprintf(const char *fmt, va_list args)
Write message to system log.
Definition: log.c:42
ANSI escape sequences.
void __attribute__((format(printf, 1, 2))) log_printf(const char *fmt
Console configuration.
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
int const char * format
Definition: xfer.h:104