summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorDaniel Kurtz <djkurtz@chromium.org>2011-08-08 15:09:46 +0800
committerPeter Hutterer <peter.hutterer@who-t.net>2011-08-22 15:49:18 +1000
commitb31d104fc09a7241856ff8d226be11ec562beac3 (patch)
tree9ed507b828ec8d8dc7c813b256846c8a85612135 /os
parentb82f934db661c59d7397ce180d08cf8f8f7118b1 (diff)
os/log: Add LogVHdrMessageVerb and friends
LogVHdrMessageVerb allows a custom header to be inserted in a log message, between the Log system's MessageType string, and a formatted variable message body. The custom header can itself be a formatted variable string. These functions can be used, for example, by driver abstraction layers to format specific driver messages in a standard format, but do it in a way that is efficient, obeys the log-layers verbosity settings, and is safe to use in signal handlers (because they don't call malloc), even for types besides X_NONE. Signed-off-by: Daniel Kurtz <djkurtz@chromium.org> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'os')
-rw-r--r--os/log.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/os/log.c b/os/log.c
index 4ff018078..2eddf066a 100644
--- a/os/log.c
+++ b/os/log.c
@@ -411,6 +411,61 @@ LogMessage(MessageType type, const char *format, ...)
va_end(ap);
}
+
+void
+LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
+ va_list msg_args, const char *hdr_format, va_list hdr_args)
+{
+ const char *type_str;
+ char tmpFormat[1024];
+ char *tmpFormat_end = &tmpFormat[sizeof(tmpFormat)];
+ char *p;
+ int left;
+
+ type_str = LogMessageTypeVerbString(type, verb);
+ if (!type_str)
+ return;
+
+ /* if type_str != "", copy it and ' ' to tmpFormat; set p after ' ' */
+ p = tmpFormat;
+ if (type_str[0] != '\0')
+ p += snprintf(tmpFormat, sizeof(tmpFormat), "%s ", type_str);
+
+ /* append as much of hdr as fits after type_str (if there was one) */
+ left = tmpFormat_end - p;
+ if (left > 1)
+ p += vsnprintf(p, left, hdr_format, hdr_args);
+
+ /* append as much of msg_format as will fit after hdr */
+ left = tmpFormat_end - p;
+ if (left > 1)
+ snprintf(p, left, "%s", msg_format);
+
+ LogVWrite(verb, tmpFormat, msg_args);
+}
+
+void
+LogHdrMessageVerb(MessageType type, int verb, const char *msg_format,
+ va_list msg_args, const char *hdr_format, ...)
+{
+ va_list hdr_args;
+
+ va_start(hdr_args, hdr_format);
+ LogVHdrMessageVerb(type, verb, msg_format, msg_args, hdr_format, hdr_args);
+ va_end(hdr_args);
+}
+
+void
+LogHdrMessage(MessageType type, const char *msg_format, va_list msg_args,
+ const char *hdr_format, ...)
+{
+ va_list hdr_args;
+
+ va_start(hdr_args, hdr_format);
+ LogVHdrMessageVerb(type, 1, msg_format, msg_args, hdr_format, hdr_args);
+ va_end(hdr_args);
+}
+
void
AbortServer(void) _X_NORETURN;