From 535003ca20a9dd00a09dd34ad26947d888aabe39 Mon Sep 17 00:00:00 2001 From: Poornima G Date: Mon, 2 Jun 2014 14:11:29 +0530 Subject: logging: Prior to log initialization, print all logs to syslog. There can be calls to gf_msg even before caling logging_init(). Currently such messages appear on stderr. In this patch, gf_msg is changed to log messages to syslog if the logging framework is not inited. Change-Id: I8fcf562f9d07b5b6b789fbd9e6f37b354de16b98 BUG: 1103623 Signed-off-by: Poornima G Reviewed-on: http://review.gluster.org/7948 Reviewed-by: Raghavendra Talur Reviewed-by: Atin Mukherjee Reviewed-by: Raghavendra G Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/logging.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'libglusterfs/src/logging.c') diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 505580d1e81..0e6e47b2106 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -2004,6 +2004,7 @@ _gf_msg (const char *domain, const char *file, const char *function, glusterfs_ctx_t *ctx = NULL; char callstr[GF_LOG_BACKTRACE_SIZE] = {0,}; int passcallstr = 0; + int log_inited = 0; /* in args check */ if (!domain || !file || !function || !fmt) { @@ -2043,21 +2044,38 @@ _gf_msg (const char *domain, const char *file, const char *function, } #endif /* HAVE_BACKTRACE */ + pthread_mutex_lock (&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + log_inited = 1; + } + } + pthread_mutex_unlock (&ctx->log.logfile_mutex); + /* form the message */ va_start (ap, fmt); ret = vasprintf (&msgstr, fmt, ap); va_end (ap); /* log */ - if (ret != -1) - ret = _gf_msg_internal (domain, file, function, line, level, - errnum, msgid, &msgstr, - (passcallstr? callstr : NULL), - (this->graph)? this->graph->id : 0); - else + if (ret != -1) { + if (!log_inited && ctx->log.gf_log_syslog) { + ret = gf_log_syslog (ctx, domain, file, function, line, + level, errnum, msgid, &msgstr, + (passcallstr? callstr : NULL), + (this->graph)? this->graph->id : 0, + gf_logformat_traditional); + } else { + ret = _gf_msg_internal (domain, file, function, line, + level, errnum, msgid, &msgstr, + (passcallstr? callstr : NULL), + (this->graph)? this->graph->id : 0); + } + } else { /* man (3) vasprintf states on error strp contents * are undefined, be safe */ msgstr = NULL; + } FREE (msgstr); -- cgit