[sheepdog] [PATCH v2] lib: choose a correct output in logger

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Jul 18 10:28:15 CEST 2013


From: Hitoshi Mitake <mitake.hitoshi at gmail.com>

Current logger chooses stderr as an output of logs in cases
logarea_init() isn't called or default formatter is used.

This patch lets logger choose stderr when a priority of logs is less
than or equal to LOG_NOTICE. If the priority is larger than or equal
to SDOG_INFO, stdout is used.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v2: put the definition of *f on the top of the block

 lib/logger.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/logger.c b/lib/logger.c
index 253163d..9fa21a5 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -402,13 +402,16 @@ static notrace void dolog(int prio, const char *func, int line,
 		}
 	} else {
 		char str_final[MAX_MSG_SIZE];
+		FILE *f;
 
 		memset(str_final, 0, MAX_MSG_SIZE);
 		memset(msg, 0, sizeof(struct logmsg));
 		init_logmsg(msg, &tv, prio, func, line);
 		len = format->formatter(str_final, MAX_MSG_SIZE, msg);
-		xwrite(fileno(stderr), str_final, len);
-		fflush(stderr);
+
+		f = SDOG_INFO <= prio ? stdout : stderr;
+		xwrite(fileno(f), str_final, len);
+		fflush(f);
 	}
 }
 
-- 
1.7.10.4




More information about the sheepdog mailing list