summaryrefslogtreecommitdiffstats
path: root/src/include/syslog.h
diff options
context:
space:
mode:
authorMichael Brown2012-03-26 20:50:50 +0200
committerMichael Brown2012-03-26 20:58:14 +0200
commit24b7296319666709ac49bedb47df18d0bc37704e (patch)
treed2c5847e0d8844ea50b7a835fe7d21fd5f556a4d /src/include/syslog.h
parent[console] Exclude text-based UI output from logfile-based consoles (diff)
downloadipxe-24b7296319666709ac49bedb47df18d0bc37704e.tar.gz
ipxe-24b7296319666709ac49bedb47df18d0bc37704e.tar.xz
ipxe-24b7296319666709ac49bedb47df18d0bc37704e.zip
[console] Add "log message" console usage and an internal syslog() call
Provide an internal syslog() function (unrelated to the syslog console) which can be used to create log messages with specified priorities. The build-time constant LOG_LEVEL can be used to select the minimum required priority for log messages. Any messages that do not have a sufficient priority will be ignored (and will be optimised away at compile-time). The default LOG_LEVEL is LOG_NONE. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/syslog.h')
-rw-r--r--src/include/syslog.h84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/include/syslog.h b/src/include/syslog.h
new file mode 100644
index 00000000..cc7b19fd
--- /dev/null
+++ b/src/include/syslog.h
@@ -0,0 +1,84 @@
+#ifndef _SYSLOG_H
+#define _SYSLOG_H
+
+/** @file
+ *
+ * System logger
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER );
+
+#include <stdarg.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
+
+extern void log_vprintf ( const char *fmt, va_list args );
+
+extern void __attribute__ (( format ( printf, 1, 2 ) ))
+log_printf ( const char *fmt, ... );
+
+/**
+ * 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 ( fmt, (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 ( fmt, ##__VA_ARGS__ ); \
+ } \
+ } while ( 0 )
+
+#endif /* _SYSLOG_H */