diff options
author | Richard Braun <rbraun@sceen.net> | 2017-06-24 01:31:08 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-06-24 01:31:08 +0200 |
commit | a2729aef568285daff96ffc5719caf8e26043ca9 (patch) | |
tree | 20eb5a30bde47a38c16cf08cda9f47bad7746816 | |
parent | aeea74bc5438895f09329ef1a3a006f251ae25ce (diff) |
kern/log: force log messages to fit in a single line
-rw-r--r-- | kern/log.c | 9 | ||||
-rw-r--r-- | kern/log.h | 6 |
2 files changed, 14 insertions, 1 deletions
@@ -22,6 +22,7 @@ #include <stddef.h> #include <stdio.h> #include <stdint.h> +#include <string.h> #include <kern/cbuf.h> #include <kern/init.h> @@ -457,6 +458,7 @@ log_vmsg(unsigned int level, const char *format, va_list ap) unsigned long flags; int nr_chars; size_t size; + char *ptr; log_record_init_produce(&record, level); nr_chars = vsnprintf(record.buffer, sizeof(record.buffer), format, ap); @@ -466,6 +468,13 @@ log_vmsg(unsigned int level, const char *format, va_list ap) goto out; } + ptr = strchr(record.buffer, '\n'); + + if (ptr != NULL) { + *ptr = '\0'; + nr_chars = ptr - record.buffer; + } + assert(nr_chars >= 0); size = offsetof(struct log_record, buffer) + nr_chars + 1; @@ -48,7 +48,11 @@ void log_start(void); /* * Generate a message and send it to the log thread. * - * Except for level, the arguments and return value are similar to printf(). + * The arguments and return value are similar to printf(), with + * these exceptions : + * - a level is associated to each log message + * - processing stops at the first terminating null byte or newline + * character, whichever occurs first * * This function may safely be called in interrupt context. */ |