iPXE
syslog.h
Go to the documentation of this file.
00001 #ifndef _SYSLOG_H
00002 #define _SYSLOG_H
00003 
00004 /** @file
00005  *
00006  * System logger
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdarg.h>
00013 #include <ipxe/ansiesc.h>
00014 #include <config/console.h>
00015 
00016 /**
00017  * @defgroup syslogpri Syslog priorities
00018  *
00019  * These values are chosen to match those used in the syslog network
00020  * protocol (RFC 5424).
00021  *
00022  * @{
00023  */
00024 
00025 /** Emergency: system is unusable */
00026 #define LOG_EMERG 0
00027 
00028 /** Alert: action must be taken immediately */
00029 #define LOG_ALERT 1
00030 
00031 /** Critical: critical conditions */
00032 #define LOG_CRIT 2
00033 
00034 /** Error: error conditions */
00035 #define LOG_ERR 3
00036 
00037 /** Warning: warning conditions */
00038 #define LOG_WARNING 4
00039 
00040 /** Notice: normal but significant conditions */
00041 #define LOG_NOTICE 5
00042 
00043 /** Informational: informational messages */
00044 #define LOG_INFO 6
00045 
00046 /** Debug: debug-level messages */
00047 #define LOG_DEBUG 7
00048 
00049 /** @} */
00050 
00051 /** Do not log any messages */
00052 #define LOG_NONE -1
00053 
00054 /** Log all messages */
00055 #define LOG_ALL LOG_DEBUG
00056 
00057 extern void log_vprintf ( const char *fmt, va_list args );
00058 
00059 extern void __attribute__ (( format ( printf, 1, 2 ) ))
00060 log_printf ( const char *fmt, ... );
00061 
00062 /** ANSI private escape sequence to set syslog priority
00063  *
00064  * @v priority          Priority
00065  */
00066 #define SYSLOG_SET_PRIORITY( priority ) \
00067         "\033[" #priority "p"
00068 
00069 /** ANSI private escape sequence to clear syslog priority */
00070 #define SYSLOG_CLEAR_PRIORITY "\033[p"
00071 
00072 /**
00073  * Write message to system log
00074  *
00075  * @v priority          Message priority
00076  * @v fmt               Format string
00077  * @v ...               Arguments
00078  */
00079 #define vsyslog( priority, fmt, args ) do {                             \
00080         if ( (priority) <= LOG_LEVEL ) {                                \
00081                 log_vprintf ( SYSLOG_SET_PRIORITY ( priority ) fmt      \
00082                               SYSLOG_CLEAR_PRIORITY, (args) );          \
00083         }                                                               \
00084         } while ( 0 )
00085 
00086 /**
00087  * Write message to system log
00088  *
00089  * @v priority          Message priority
00090  * @v fmt               Format string
00091  * @v ...               Arguments
00092  */
00093 #define syslog( priority, fmt, ... ) do {                               \
00094         if ( (priority) <= LOG_LEVEL ) {                                \
00095                 log_printf ( SYSLOG_SET_PRIORITY ( priority ) fmt       \
00096                              SYSLOG_CLEAR_PRIORITY, ##__VA_ARGS__ );    \
00097         }                                                               \
00098         } while ( 0 )
00099 
00100 #endif /* _SYSLOG_H */