summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/logging.c73
-rw-r--r--libglusterfs/src/logging.h1
-rwxr-xr-xtests/bugs/core/log-bug-1362520.t43
3 files changed, 75 insertions, 42 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c
index 4408c5f674c..55cf2e97d2c 100644
--- a/libglusterfs/src/logging.c
+++ b/libglusterfs/src/logging.c
@@ -164,7 +164,6 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level)
xlator_t *xl = this;
if (!xl)
return;
- xl->ctx->log.gf_log_xl_log_set = 1;
xl->loglevel = level;
}
@@ -770,6 +769,30 @@ set_sys_log_level (gf_loglevel_t level)
ctx->log.sys_log_level = level;
}
+/* Check if we should be logging
+ * Return value: _gf_false : Print the log
+ * _gf_true : Do not Print the log
+ */
+static gf_boolean_t
+skip_logging (xlator_t *this, gf_loglevel_t level)
+{
+ gf_boolean_t ret = _gf_false;
+ gf_loglevel_t existing_level = GF_LOG_NONE;
+
+ if (level == GF_LOG_NONE) {
+ ret = _gf_true;
+ goto out;
+ }
+
+ existing_level = this->loglevel ? this->loglevel : this->ctx->log.loglevel;
+ if (level > existing_level) {
+ ret = _gf_true;
+ goto out;
+ }
+out:
+ return ret;
+}
+
int
_gf_log_callingfn (const char *domain, const char *file, const char *function,
int line, gf_loglevel_t level, const char *fmt, ...)
@@ -793,11 +816,7 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
static char *level_strings[] = {"", /* NONE */
@@ -984,11 +1003,7 @@ _gf_msg_plain (gf_loglevel_t level, const char *fmt, ...)
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
va_start (ap, fmt);
@@ -1020,11 +1035,7 @@ _gf_msg_vplain (gf_loglevel_t level, const char *fmt, va_list ap)
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
ret = vasprintf (&msg, fmt, ap);
@@ -1052,11 +1063,7 @@ _gf_msg_plain_nomem (gf_loglevel_t level, const char *msg)
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
ret = _gf_msg_plain_internal (level, msg);
@@ -1084,11 +1091,7 @@ _gf_msg_backtrace_nomem (gf_loglevel_t level, int stacksize)
if (ctx->log.logger != gf_logger_glusterlog)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
bt_size = backtrace (array, ((stacksize <= 200)? stacksize : 200));
@@ -1171,11 +1174,7 @@ _gf_msg_nomem (const char *domain, const char *file,
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
if (!domain || !file || !function) {
@@ -2040,11 +2039,7 @@ _gf_msg (const char *domain, const char *file, const char *function,
}
/* check if we should be logging */
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
if (trace) {
@@ -2121,11 +2116,7 @@ _gf_log (const char *domain, const char *file, const char *function, int line,
if (!ctx)
goto out;
- if (ctx->log.gf_log_xl_log_set) {
- if (this->loglevel && (level > this->loglevel))
- goto out;
- }
- if (level > ctx->log.loglevel || level == GF_LOG_NONE)
+ if (skip_logging (this, level))
goto out;
static char *level_strings[] = {"", /* NONE */
diff --git a/libglusterfs/src/logging.h b/libglusterfs/src/logging.h
index f3a694ceefd..a6e318dc3fa 100644
--- a/libglusterfs/src/logging.h
+++ b/libglusterfs/src/logging.h
@@ -100,7 +100,6 @@ typedef struct gf_log_handle_ {
gf_loglevel_t loglevel;
int gf_log_syslog;
gf_loglevel_t sys_log_level;
- char gf_log_xl_log_set;
char *filename;
FILE *logfile;
FILE *gf_log_logfile;
diff --git a/tests/bugs/core/log-bug-1362520.t b/tests/bugs/core/log-bug-1362520.t
new file mode 100755
index 00000000000..cde854c3349
--- /dev/null
+++ b/tests/bugs/core/log-bug-1362520.t
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+#. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+#Basic checks
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info
+
+#Create a distributed volume
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1};
+TEST $CLI volume start $V0
+
+# Mount FUSE without selinux:
+TEST glusterfs -s $H0 --volfile-id $V0 $@ $M0
+
+#Get the client log file
+log_wd=$(gluster --print-logdir)
+log_id=${M0:1} # Remove initial slash
+log_id=${log_id//\//-} # Replace remaining slashes with dashes
+log_file=$log_wd/$log_id.log
+
+#Set the client xlator log-level to TRACE and check if the TRACE logs get
+#printed
+TEST setfattr -n trusted.glusterfs.$V0-client-0.set-log-level -v TRACE $M0
+TEST ! stat $M0/xyz
+grep -q " T \[rpc-clnt\.c" $log_file
+res=$?
+EXPECT '0' echo $res
+
+#Set the client xlator log-level to INFO and make sure the TRACE logs do
+#not get printed
+echo > $log_file
+TEST setfattr -n trusted.glusterfs.$V0-client-0.set-log-level -v INFO $M0
+TEST ! stat $M0/xyz
+grep -q " T \[rpc-clnt\.c" $log_file
+res=$?
+EXPECT_NOT '0' echo $res
+
+cleanup;