[PATCH 2/3] log: Add pr_cont helper
Cyrill Gorcunov
gorcunov at openvz.org
Tue Aug 20 12:07:14 EDT 2013
Sometimes we split output printing in several pr_ calls, which
causes log engine to inject time delta at the front of the record.
For example
| (00.007461) Obtaining task stat ... (00.007497)
instead of ending delta there should be plain \n.
For this sake we introduce pr_cont() helper. It works similar
to what pr_cont in kernel does -- continues printing a line.
Note it's not multithread safe so don't use it outside of
dumping procedure. At least for now.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/log.h | 4 ++++
log.c | 15 +++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/include/log.h b/include/log.h
index a38f441..30a6f24 100644
--- a/include/log.h
+++ b/include/log.h
@@ -57,4 +57,8 @@ extern void print_on_level(unsigned int loglevel, const char *format, ...)
#define pr_perror(fmt, ...) \
pr_err(fmt ": %m\n", ##__VA_ARGS__)
+#define pr_cont(fmt, ...) \
+ print_on_level(LOG_CONT, \
+ LOG_PREFIX fmt, ##__VA_ARGS__)
+
#endif /* __CR_LOG_H__ */
diff --git a/log.c b/log.c
index feb2263..fbbcf52 100644
--- a/log.c
+++ b/log.c
@@ -20,6 +20,7 @@
#define DEFAULT_LOGFD STDERR_FILENO
static unsigned int current_loglevel = DEFAULT_LOGLEVEL;
+static unsigned int prev_print_at = DEFAULT_LOGLEVEL;
static char buffer[PAGE_SIZE];
static char buf_off = 0;
@@ -161,15 +162,25 @@ static void __print_on_level(unsigned int loglevel, const char *format, va_list
{
int fd, size, ret, off;
- if (unlikely(loglevel == LOG_MSG)) {
+ switch (loglevel) {
+ case LOG_MSG:
fd = STDOUT_FILENO;
off = buf_off;
- } else {
+ break;
+ case LOG_CONT:
+ if (prev_print_at > current_loglevel)
+ return;
+ fd = log_get_fd();
+ off = buf_off;
+ break;
+ default:
+ prev_print_at = loglevel;
if (loglevel > current_loglevel)
return;
fd = log_get_fd();
print_ts();
off = 0;
+ break;
}
size = vsnprintf(buffer + buf_off, PAGE_SIZE - buf_off, format, params);
--
1.8.1.4
--8t9RHnE3ZwKMSgU+--
More information about the CRIU
mailing list