[sheepdog] [PATCH v2 2/2] logger: use simpler formatter by default

MORITA Kazutaka morita.kazutaka at gmail.com
Sat Jul 13 16:29:22 CEST 2013


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

The current log format is expected to be used for server daemons and
not appropriate for collie and sheepfs.  This patch introduces a
simpler formatter for them.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 lib/logger.c        |   18 ++++++++++++++++--
 sheep/sheep.c       |    2 +-
 shepherd/shepherd.c |    2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/logger.c b/lib/logger.c
index ad2bc6a..253163d 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -205,8 +205,8 @@ static void notrace free_logarea(void)
 	shmdt(la);
 }
 
-static notrace int default_log_formatter(char *buff, size_t size,
-				const struct logmsg *msg)
+static notrace int server_log_formatter(char *buff, size_t size,
+					const struct logmsg *msg)
 {
 	char *p = buff;
 	struct tm tm;
@@ -249,6 +249,20 @@ static notrace int default_log_formatter(char *buff, size_t size,
 
 	return p - buff;
 }
+log_format_register("server", server_log_formatter);
+
+static notrace int default_log_formatter(char *buff, size_t size,
+					 const struct logmsg *msg)
+{
+	int len;
+
+	pstrcpy(buff, size, msg->str);
+	len = strlen(buff);
+	if (len > 0 && buff[len - 1] != '\n' && size > len)
+		buff[len++] = '\n';
+
+	return len;
+}
 log_format_register("default", default_log_formatter);
 
 static notrace int json_log_formatter(char *buff, size_t size,
diff --git a/sheep/sheep.c b/sheep/sheep.c
index b1d8294..c8d4478 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -592,7 +592,7 @@ int main(int argc, char **argv)
 	int64_t zone = -1;
 	struct cluster_driver *cdrv;
 	struct option *long_options;
-	const char *log_format = "default", *http_address = NULL;
+	const char *log_format = "server", *http_address = NULL;
 	static struct logger_user_info sheep_info;
 
 	install_crash_handler(crash_handler);
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index f85832f..575097f 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -780,7 +780,7 @@ int main(int argc, char **argv)
 	bool daemonize = true;
 	int log_level = SDOG_INFO;
 	const char *log_file = "/var/log/shepherd.log";
-	const char *log_format = "default";
+	const char *log_format = "server";
 	struct logger_user_info shepherd_info;
 
 	int port = SHEPHERD_PORT;
-- 
1.7.9.5




More information about the sheepdog mailing list