[sheepdog] [PATCH 7/7] logger: show log priority in sheep.log

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Aug 13 12:09:31 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

This helps us to find important log messages from sheep.log.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 lib/logger.c |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/logger.c b/lib/logger.c
index 31ce251..072ac6f 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -49,6 +49,17 @@ static const char * const log_color[] = {
 	[SDOG_DEBUG] = TEXT_GREEN,
 };
 
+static const char * const log_prio_str[] = {
+	[SDOG_EMERG]   = "EMERG",
+	[SDOG_ALERT]   = "ALERT",
+	[SDOG_CRIT]    = "CRIT",
+	[SDOG_ERR]     = "ERROR",
+	[SDOG_WARNING] = "WARN",
+	[SDOG_NOTICE]  = "NOTICE",
+	[SDOG_INFO]    = "INFO",
+	[SDOG_DEBUG]   = "DEBUG",
+};
+
 static struct logger_user_info *logger_user_info;
 
 static void dolog(int prio, const char *func, int line, const char *fmt,
@@ -232,7 +243,9 @@ static int server_log_formatter(char *buff, size_t size,
 	p += len;
 	size -= len;
 
-	len = snprintf(p, size, "%s[%s] %s(%d) %s%s%s",
+	len = snprintf(p, size, "%s%6s %s[%s] %s(%d) %s%s%s",
+		       colorize ? log_color[msg->prio] : "",
+		       log_prio_str[msg->prio],
 		       colorize ? TEXT_YELLOW : "",
 		       format_thread_name(thread_name, sizeof(thread_name),
 					  msg->worker_name, msg->worker_idx),
-- 
1.7.9.5




More information about the sheepdog mailing list