From bdd0bb357f477db83feaaf9eb7ba2534b87f24fa Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 11 Jul 2012 17:09:50 +0930 Subject: [PATCH] Improve logging config options Rename config option "logfile" to "log.file" Add "log.show_pid" boolean Add "log.show_time" boolean --- log.c | 27 +++++++++++++++++++-------- tests/rhizomeprotocol | 2 ++ tests/server | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/log.c b/log.c index 99b2908b..316c68c6 100644 --- a/log.c +++ b/log.c @@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. unsigned int debug = 0; static FILE *logfile = NULL; -static int log_pid = 1; -static int log_time = 1; +static int flag_show_pid = -1; +static int flag_show_time = -1; /* The logbuf is used to accumulate log messages before the log file is open and ready for writing. @@ -41,9 +41,6 @@ static struct strbuf logbuf = STRUCT_STRBUF_EMPTY; FILE *open_logging() { if (!logfile) { -#ifdef ANDROID - log_pid = log_time = 0; -#endif const char *logpath = getenv("SERVALD_LOG_FILE"); if (!logpath) { // If the configuration is locked (eg, it called WHY() or DEBUG() while initialising, which @@ -67,6 +64,20 @@ FILE *open_logging() return logfile; } +static int show_pid() +{ + if (flag_show_pid < 0 && !confLocked()) + flag_show_pid = confValueGetBoolean("log.show_pid", 0); + return flag_show_pid; +} + +static int show_time() +{ + if (flag_show_time < 0 && !confLocked()) + flag_show_time = confValueGetBoolean("log.show_time", 0); + return flag_show_time; +} + void close_logging() { if (logfile) { @@ -89,7 +100,6 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun if (strbuf_is_empty(&logbuf)) strbuf_init(&logbuf, _log_buf, sizeof _log_buf); #ifndef ANDROID - FILE *logf = open_logging(); const char *levelstr = "UNKWN:"; switch (level) { case LOG_LEVEL_FATAL: levelstr = "FATAL:"; break; @@ -100,9 +110,9 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun } strbuf_sprintf(&logbuf, "%-6s ", levelstr); #endif - if (log_pid) + if (show_pid()) strbuf_sprintf(&logbuf, "[%5u] ", getpid()); - if (log_time) { + if (show_time()) { struct timeval tv; if (gettimeofday(&tv, NULL) == -1) { strbuf_puts(&logbuf, "NOTIME______"); @@ -130,6 +140,7 @@ void vlogMessage(int level, const char *file, unsigned int line, const char *fun __android_log_print(alevel, "servald", "%s", strbuf_str(&logbuf)); strbuf_reset(&logbuf); #else + FILE *logf = open_logging(); if (logf) { fputs(strbuf_str(&logbuf), logf); if (strbuf_overrun(&logbuf)) diff --git a/tests/rhizomeprotocol b/tests/rhizomeprotocol index a2f1e711..ca9582a7 100755 --- a/tests/rhizomeprotocol +++ b/tests/rhizomeprotocol @@ -40,6 +40,8 @@ setup_rhizome() { # Called by start_servald_instances for each instance. configure_servald_server() { + executeOk_servald config set log.show_pid on + executeOk_servald config set log.show_time on executeOk_servald config set debug.rhizome on executeOk_servald config set debug.rhizomesync on executeOk_servald config set mdp.wifi.tick_ms 100 diff --git a/tests/server b/tests/server index 09eeac59..4cdca0db 100755 --- a/tests/server +++ b/tests/server @@ -52,7 +52,7 @@ test_StartCreateInstanceDir() { doc_StartLogfile="Starting server gives no errors" setup_StartLogfile() { setup - executeOk_servald config set logfile "$PWD/log" + executeOk_servald config set log.file "$PWD/log" } test_StartLogfile() { executeOk $servald start