Browse Source

[syslog] Pass internal syslog() priority through to syslog console

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>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
3ff7927d2f
4 changed files with 53 additions and 14 deletions
  1. 7
    0
      src/include/ipxe/ansiesc.h
  2. 4
    4
      src/include/ipxe/syslog.h
  3. 21
    8
      src/include/syslog.h
  4. 21
    2
      src/net/udp/syslog.c

+ 7
- 0
src/include/ipxe/ansiesc.h View File

113
 /** Select graphic rendition */
113
 /** Select graphic rendition */
114
 #define ANSIESC_SGR 'm'
114
 #define ANSIESC_SGR 'm'
115
 
115
 
116
+/** Explicit log message priority
117
+ *
118
+ * This is an iPXE private sequence identifier.  (The range 'p' to '~'
119
+ * is reserved for private sequences.)
120
+ */
121
+#define ANSIESC_LOG_PRIORITY 'p'
122
+
116
 /** @} */
123
 /** @} */
117
 
124
 
118
 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );
125
 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );

+ 4
- 4
src/include/ipxe/syslog.h View File

20
  */
20
  */
21
 #define SYSLOG_BUFSIZE 128
21
 #define SYSLOG_BUFSIZE 128
22
 
22
 
23
-/** Syslog facility
23
+/** Syslog default facility
24
  *
24
  *
25
  * This is a policy decision
25
  * This is a policy decision
26
  */
26
  */
27
-#define SYSLOG_FACILITY 0 /* kernel */
27
+#define SYSLOG_DEFAULT_FACILITY 0 /* kernel */
28
 
28
 
29
-/** Syslog severity
29
+/** Syslog default severity
30
  *
30
  *
31
  * This is a policy decision
31
  * This is a policy decision
32
  */
32
  */
33
-#define SYSLOG_SEVERITY LOG_INFO
33
+#define SYSLOG_DEFAULT_SEVERITY LOG_INFO
34
 
34
 
35
 /** Syslog priority */
35
 /** Syslog priority */
36
 #define SYSLOG_PRIORITY( facility, severity ) ( 8 * (facility) + (severity) )
36
 #define SYSLOG_PRIORITY( facility, severity ) ( 8 * (facility) + (severity) )

+ 21
- 8
src/include/syslog.h View File

10
 FILE_LICENCE ( GPL2_OR_LATER );
10
 FILE_LICENCE ( GPL2_OR_LATER );
11
 
11
 
12
 #include <stdarg.h>
12
 #include <stdarg.h>
13
+#include <ipxe/ansiesc.h>
13
 #include <config/console.h>
14
 #include <config/console.h>
14
 
15
 
15
 /**
16
 /**
55
 extern void __attribute__ (( format ( printf, 1, 2 ) ))
56
 extern void __attribute__ (( format ( printf, 1, 2 ) ))
56
 log_printf ( const char *fmt, ... );
57
 log_printf ( const char *fmt, ... );
57
 
58
 
59
+/** ANSI private escape sequence to set syslog priority
60
+ *
61
+ * @v priority		Priority
62
+ */
63
+#define SYSLOG_SET_PRIORITY( priority ) \
64
+	"\033[" #priority "p"
65
+
66
+/** ANSI private escape sequence to clear syslog priority */
67
+#define SYSLOG_CLEAR_PRIORITY "\033[p"
68
+
58
 /**
69
 /**
59
  * Write message to system log
70
  * Write message to system log
60
  *
71
  *
62
  * @v fmt		Format string
73
  * @v fmt		Format string
63
  * @v ...		Arguments
74
  * @v ...		Arguments
64
  */
75
  */
65
-#define vsyslog( priority, fmt, args ) do {		\
76
+#define vsyslog( priority, fmt, args ) do {				\
66
-	if ( (priority) <= LOG_LEVEL ) {		\
77
+	if ( (priority) <= LOG_LEVEL ) {				\
67
-		log_vprintf ( fmt, (args) );		\
78
+		log_vprintf ( SYSLOG_SET_PRIORITY ( priority ) fmt	\
68
-	}						\
79
+			      SYSLOG_CLEAR_PRIORITY, (args) );		\
80
+	}								\
69
 	} while ( 0 )
81
 	} while ( 0 )
70
 
82
 
71
 /**
83
 /**
75
  * @v fmt		Format string
87
  * @v fmt		Format string
76
  * @v ...		Arguments
88
  * @v ...		Arguments
77
  */
89
  */
78
-#define syslog( priority, fmt, ... ) do {		\
90
+#define syslog( priority, fmt, ... ) do {				\
79
-	if ( (priority) <= LOG_LEVEL ) {		\
91
+	if ( (priority) <= LOG_LEVEL ) {				\
80
-		log_printf ( fmt, ##__VA_ARGS__ );	\
92
+		log_printf ( SYSLOG_SET_PRIORITY ( priority ) fmt	\
81
-	}						\
93
+			     SYSLOG_CLEAR_PRIORITY, ##__VA_ARGS__ );	\
94
+	}								\
82
 	} while ( 0 )
95
 	} while ( 0 )
83
 
96
 
84
 #endif /* _SYSLOG_H */
97
 #endif /* _SYSLOG_H */

+ 21
- 2
src/net/udp/syslog.c View File

68
 /** Syslog line buffer */
68
 /** Syslog line buffer */
69
 static char syslog_buffer[SYSLOG_BUFSIZE];
69
 static char syslog_buffer[SYSLOG_BUFSIZE];
70
 
70
 
71
+/** Syslog severity */
72
+static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY;
73
+
74
+/**
75
+ * Handle ANSI set syslog priority (private sequence)
76
+ *
77
+ * @v count		Parameter count
78
+ * @v params		List of graphic rendition aspects
79
+ */
80
+static void syslog_handle_priority ( unsigned int count __unused,
81
+				     int params[] ) {
82
+	if ( params[0] >= 0 ) {
83
+		syslog_severity = params[0];
84
+	} else {
85
+		syslog_severity = SYSLOG_DEFAULT_SEVERITY;
86
+	}
87
+}
88
+
71
 /** Syslog ANSI escape sequence handlers */
89
 /** Syslog ANSI escape sequence handlers */
72
 static struct ansiesc_handler syslog_handlers[] = {
90
 static struct ansiesc_handler syslog_handlers[] = {
91
+	{ ANSIESC_LOG_PRIORITY, syslog_handle_priority },
73
 	{ 0, NULL }
92
 	{ 0, NULL }
74
 };
93
 };
75
 
94
 
106
 
125
 
107
 	/* Send log message */
126
 	/* Send log message */
108
 	if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
127
 	if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
109
-				  SYSLOG_PRIORITY ( SYSLOG_FACILITY,
128
+				  SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
110
-						    SYSLOG_SEVERITY ),
129
+						    syslog_severity ),
111
 				  syslog_buffer ) ) != 0 ) {
130
 				  syslog_buffer ) ) != 0 ) {
112
 		DBG ( "SYSLOG could not send log message: %s\n",
131
 		DBG ( "SYSLOG could not send log message: %s\n",
113
 		      strerror ( rc ) );
132
 		      strerror ( rc ) );

Loading…
Cancel
Save