summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPoornima G <pgurusid@redhat.com>2014-06-02 14:11:29 +0530
committerVijay Bellur <vbellur@redhat.com>2014-06-05 22:12:40 -0700
commit535003ca20a9dd00a09dd34ad26947d888aabe39 (patch)
treea8dbfb2932a95f84a62b9ba48b3739c1f839296a
parent42b956971c47fd0708cbbd17ce8c78c2ed79bfba (diff)
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 <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/7948 Reviewed-by: Raghavendra Talur <rtalur@redhat.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-by: Raghavendra G <rgowdapp@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--libglusterfs/src/logging.c30
1 files changed, 24 insertions, 6 deletions
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);