[sheepdog] [PATCH v5] logger: rename and change a role of select_log_formatter()
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Tue Feb 5 10:46:46 CET 2013
This patch renames select_log_formatter(). The new name is
early_log_init().
early_log_init() is also used for selecting log formatter, but it
also used for registering information of logger user. The information
is registered as 2nd parameter of the function which is typed struct
logger_user_info.
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v5: writing initial log entry with user specified callback is removed
8<---
include/logger.h | 7 ++++++-
lib/logger.c | 27 +++++++++++++++++++++++----
sheep/sheep.c | 6 ++++--
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/include/logger.h b/include/logger.h
index 309b484..0ed457d 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -21,7 +21,12 @@
#define MAX_MSG_SIZE 256
#define MAX_THREAD_NAME_LEN 20
-void select_log_formatter(const char *format_name);
+struct logger_user_info {
+ int port;
+};
+
+void early_log_init(const char *format_name,
+ struct logger_user_info *user_info);
int log_init(const char *progname, int size, bool to_stdout, int level,
char *outfile);
void log_close(void);
diff --git a/lib/logger.c b/lib/logger.c
index f3f03e3..0b180d6 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -36,6 +36,8 @@
#include "logger.h"
#include "util.h"
+struct logger_user_info *logger_user_info;
+
static void dolog(int prio, const char *func, int line, const char *fmt,
va_list ap) __attribute__ ((format (printf, 4, 0)));
@@ -208,7 +210,22 @@ static notrace int json_log_formatter(char *buff, size_t size,
int i, body_len;
char *p = buff;
- snprintf(p, size, "{");
+ snprintf(p, size, "{ \"user_info\": {");
+ p += strlen(p);
+
+ snprintf(p, size - strlen(buff), "\"program_name\": \"%s\", ",
+ log_name);
+ p += strlen(p);
+
+ assert(logger_user_info);
+ snprintf(p, size - strlen(buff), "\"port\": %d",
+ logger_user_info->port);
+ p += strlen(p);
+
+ snprintf(p, size - strlen(buff), "},");
+ p += strlen(p);
+
+ snprintf(p, size - strlen(buff), "\"body\": {");
p += strlen(p);
snprintf(p, size - strlen(buff), "\"second\": %lu", msg->tv.tv_sec);
@@ -235,7 +252,7 @@ static notrace int json_log_formatter(char *buff, size_t size,
snprintf(p, size - strlen(buff), ", \"line\": %d", msg->line);
p += strlen(p);
- snprintf(p, size - strlen(buff), ", \"body\": \"");
+ snprintf(p, size - strlen(buff), ", \"msg\": \"");
p += strlen(p);
body_len = strlen(msg->str) - 1;
@@ -246,7 +263,7 @@ static notrace int json_log_formatter(char *buff, size_t size,
*p++ = msg->str[i];
}
- snprintf(p, size - strlen(buff), "\"}\n");
+ snprintf(p, size - strlen(buff), "\"} }\n");
p += strlen(p);
return p - buff;
@@ -499,10 +516,12 @@ static notrace void logger(char *log_dir, char *outfile)
exit(0);
}
-void select_log_formatter(const char *format_name)
+void early_log_init(const char *format_name, struct logger_user_info *user_info)
{
struct log_format *f;
+ logger_user_info = user_info;
+
list_for_each_entry(f, &log_formats, list) {
if (!strcmp(f->name, format_name)) {
format = f;
diff --git a/sheep/sheep.c b/sheep/sheep.c
index a9b9bdb..1d95819 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -432,6 +432,7 @@ int main(int argc, char **argv)
struct cluster_driver *cdrv;
struct option *long_options;
const char *log_format = "default";
+ static struct logger_user_info sheep_info;
signal(SIGPIPE, SIG_IGN);
@@ -577,10 +578,11 @@ int main(int argc, char **argv)
}
/*
- * select_log_formatter() must be called before any calling of
+ * early_log_init() must be called before any calling of
* sd_printf() series
*/
- select_log_formatter(log_format);
+ sheep_info.port = port;
+ early_log_init(log_format, &sheep_info);
if (nr_vnodes == 0) {
sys->gateway_only = true;
--
1.7.2.5
More information about the sheepdog
mailing list