Parcourir la 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 il y a 12 ans
Parent
révision
3ff7927d2f
4 fichiers modifiés avec 53 ajouts et 14 suppressions
  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 Voir le fichier

@@ -113,6 +113,13 @@ struct ansiesc_context {
113 113
 /** Select graphic rendition */
114 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 125
 extern int ansiesc_process ( struct ansiesc_context *ctx, int c );

+ 4
- 4
src/include/ipxe/syslog.h Voir le fichier

@@ -20,17 +20,17 @@ FILE_LICENCE ( GPL2_OR_LATER );
20 20
  */
21 21
 #define SYSLOG_BUFSIZE 128
22 22
 
23
-/** Syslog facility
23
+/** Syslog default facility
24 24
  *
25 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 31
  * This is a policy decision
32 32
  */
33
-#define SYSLOG_SEVERITY LOG_INFO
33
+#define SYSLOG_DEFAULT_SEVERITY LOG_INFO
34 34
 
35 35
 /** Syslog priority */
36 36
 #define SYSLOG_PRIORITY( facility, severity ) ( 8 * (facility) + (severity) )

+ 21
- 8
src/include/syslog.h Voir le fichier

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

+ 21
- 2
src/net/udp/syslog.c Voir le fichier

@@ -68,8 +68,27 @@ static struct interface syslogger = INTF_INIT ( syslogger_desc );
68 68
 /** Syslog line buffer */
69 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 89
 /** Syslog ANSI escape sequence handlers */
72 90
 static struct ansiesc_handler syslog_handlers[] = {
91
+	{ ANSIESC_LOG_PRIORITY, syslog_handle_priority },
73 92
 	{ 0, NULL }
74 93
 };
75 94
 
@@ -106,8 +125,8 @@ static void syslog_putchar ( int character ) {
106 125
 
107 126
 	/* Send log message */
108 127
 	if ( ( rc = xfer_printf ( &syslogger, "<%d>ipxe: %s",
109
-				  SYSLOG_PRIORITY ( SYSLOG_FACILITY,
110
-						    SYSLOG_SEVERITY ),
128
+				  SYSLOG_PRIORITY ( SYSLOG_DEFAULT_FACILITY,
129
+						    syslog_severity ),
111 130
 				  syslog_buffer ) ) != 0 ) {
112 131
 		DBG ( "SYSLOG could not send log message: %s\n",
113 132
 		      strerror ( rc ) );

Chargement…
Annuler
Enregistrer