]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[syslog] Pass internal syslog() priority through to syslog console
authorMichael Brown <mcb30@ipxe.org>
Mon, 26 Mar 2012 19:23:30 +0000 (20:23 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 26 Mar 2012 20:58:58 +0000 (21:58 +0100)
Use a private ANSI escape sequence to convey the priority of an
internal syslog() message through to the syslog server.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/ansiesc.h
src/include/ipxe/syslog.h
src/include/syslog.h
src/net/udp/syslog.c

index 35438e43a593b768d9975b958e0d851bdf092008..c00af258a8aa69cc5bf768de1277357927846a9f 100644 (file)
@@ -113,6 +113,13 @@ struct ansiesc_context {
 /** Select graphic rendition */
 #define ANSIESC_SGR 'm'
 
+/** Explicit log message priority
+ *
+ * This is an iPXE private sequence identifier.  (The range 'p' to '~'
+ * is reserved for private sequences.)
+ */
+#define ANSIESC_LOG_PRIORITY 'p'
+
 /** @} */
 
 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
index 256ac76138920063c1e582c2c151f500c8f37a75..035ca67000089f478ee78eee8f4eb269d38f307a 100644 (file)
@@ -20,17 +20,17 @@ FILE_LICENCE ( GPL2_OR_LATER );
  */
 #define SYSLOG_BUFSIZE 128
 
-/** Syslog facility
+/** Syslog default facility
  *
  * This is a policy decision
  */
-#define SYSLOG_FACILITY 0 /* kernel */
+#define SYSLOG_DEFAULT_FACILITY 0 /* kernel */
 
-/** Syslog severity
+/** Syslog default severity
  *
  * This is a policy decision
  */
-#define SYSLOG_SEVERITY LOG_INFO
+#define SYSLOG_DEFAULT_SEVERITY LOG_INFO
 
 /** Syslog priority */
 #define SYSLOG_PRIORITY( facility, severity ) ( 8 * (facility) + (severity) )
index cc7b19fd51f2b2bd4b35f0139abdff308fe2035e..3dfc11b9656a2f0776bced6061679b9b7d728118 100644 (file)
@@ -10,6 +10,7 @@
 FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <stdarg.h>
+#include <ipxe/ansiesc.h>
 #include <config/console.h>
 
 /**
@@ -55,6 +56,16 @@ 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
  *
@@ -62,10 +73,11 @@ log_printf ( const char *fmt, ... );
  * @v fmt              Format string
  * @v ...              Arguments
  */
-#define vsyslog( priority, fmt, args ) do {            \
-       if ( (priority) <= LOG_LEVEL ) {                \
-               log_vprintf ( fmt, (args) );            \
-       }                                               \
+#define vsyslog( priority, fmt, args ) do {                            \
+       if ( (priority) <= LOG_LEVEL ) {                                \
+               log_vprintf ( SYSLOG_SET_PRIORITY ( priority ) fmt      \
+                             SYSLOG_CLEAR_PRIORITY, (args) );          \
+       }                                                               \
        } while ( 0 )
 
 /**
@@ -75,10 +87,11 @@ log_printf ( const char *fmt, ... );
  * @v fmt              Format string
  * @v ...              Arguments
  */
-#define syslog( priority, fmt, ... ) do {              \
-       if ( (priority) <= LOG_LEVEL ) {                \
-               log_printf ( fmt, ##__VA_ARGS__ );      \
-       }                                               \
+#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 */
index caa0d0b2925e786e5b0957d1e886a756f39b0b83..4a2653148dbe1efd5b602d7f2c7fe75ba7b1af7a 100644 (file)
@@ -68,8 +68,27 @@ static struct interface syslogger = INTF_INIT ( syslogger_desc );
 /** Syslog line buffer */
 static char syslog_buffer[SYSLOG_BUFSIZE];
 
+/** Syslog severity */
+static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY;
+
+/**
+ * Handle ANSI set syslog priority (private sequence)
+ *
+ * @v count            Parameter count
+ * @v params           List of graphic rendition aspects
+ */
+static void syslog_handle_priority ( unsigned int count __unused,
+                                    int params[] ) {
+       if ( params[0] >= 0 ) {
+               syslog_severity = params[0];
+       } else {
+               syslog_severity = SYSLOG_DEFAULT_SEVERITY;
+       }
+}
+
 /** Syslog ANSI escape sequence handlers */
 static struct ansiesc_handler syslog_handlers[] = {
+       { ANSIESC_LOG_PRIORITY, syslog_handle_priority },
        { 0, NULL }
 };
 
@@ -106,8 +125,8 @@ static void syslog_putchar ( int character ) {
 
        /* Send log message */
        if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
-                                 SYSLOG_PRIORITY ( SYSLOG_FACILITY,
-                                                   SYSLOG_SEVERITY ),
+                                 SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
+                                                   syslog_severity ),
                                  syslog_buffer ) ) != 0 ) {
                DBG ( "SYSLOG could not send log message: %s\n",
                      strerror ( rc ) );