summaryrefslogtreecommitdiffstats
path: root/utils/utils.h
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-06-04 12:27:27 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-06-05 22:46:33 +0530
commitb5337c894f66661fb6a863467bcfac3fa12eaa7c (patch)
tree2f501430a21f65fffa718413d8c159d1346f240a /utils/utils.h
parentbc283e0e6924d83044f6cbb8e3ad5e35c29a8c3d (diff)
logger: filter log messages based on severity level
This patch adds '--log-level' options supported log levels: { "NONE", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE" } TRACE being max logging $ gluster-blockd --help [...] --log-level <LOGLEVEL> Logging severity. Valid options are, TRACE, DEBUG, INFO, WARNING, ERROR and NONE [default: INFO] [...] Change-Id: I5a387eea3e7e7be10a0b56102a61eb81b4ebf2fa Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'utils/utils.h')
-rw-r--r--utils/utils.h40
1 files changed, 24 insertions, 16 deletions
diff --git a/utils/utils.h b/utils/utils.h
index 4a544ef..ef5aadc 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -77,22 +77,26 @@
fprintf(stdout, fmt, __VA_ARGS__); \
} while (0)
-# define LOG(str, level, fmt, ...) \
- do { \
- FILE *fd; \
- if (!strcmp(str, "mgmt")) \
- fd = fopen (DAEMON_LOG_FILE, "a"); \
- else if (strcmp(str, "cli")) \
- fd = fopen (CLI_LOG_FILE, "a"); \
- else if (strcmp(str, "gfapi")) \
- fd = fopen (GFAPI_LOG_FILE, "a"); \
- else \
- fd = stderr; \
- fprintf(fd, "[%lu] %s: " fmt " [at %s+%d :<%s>]\n", \
- (unsigned long)time(NULL), LogLevelLookup[level],\
- __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \
- if (fd != stderr) \
- fclose(fd); \
+extern size_t logLevel;
+
+# define LOG(str, level, fmt, ...) \
+ do { \
+ FILE *fd; \
+ if (level <= logLevel) { \
+ if (!strcmp(str, "mgmt")) \
+ fd = fopen (DAEMON_LOG_FILE, "a"); \
+ else if (strcmp(str, "cli")) \
+ fd = fopen (CLI_LOG_FILE, "a"); \
+ else if (strcmp(str, "gfapi")) \
+ fd = fopen (GFAPI_LOG_FILE, "a"); \
+ else \
+ fd = stderr; \
+ fprintf(fd, "[%lu] %s: " fmt " [at %s+%d :<%s>]\n", \
+ (unsigned long)time(NULL), LogLevelLookup[level],\
+ __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \
+ if (fd != stderr) \
+ fclose(fd); \
+ } \
} while (0)
# define GB_METALOCK_OR_GOTO(lkfd, volume, errCode, errMsg, label) \
@@ -253,6 +257,7 @@ typedef enum gbDaemonCmdlineOption {
GB_DAEMON_VERSION = 2,
GB_DAEMON_USAGE = 3,
GB_DAEMON_GLFS_LRU_COUNT = 4,
+ GB_DAEMON_LOG_LEVEL = 5,
GB_DAEMON_OPT_MAX
} gbDaemonCmdlineOption;
@@ -263,6 +268,7 @@ static const char *const gbDaemonCmdlineOptLookup[] = {
[GB_DAEMON_VERSION] = "version",
[GB_DAEMON_USAGE] = "usage",
[GB_DAEMON_GLFS_LRU_COUNT] = "glfs-lru-count",
+ [GB_DAEMON_LOG_LEVEL] = "log-level",
[GB_DAEMON_OPT_MAX] = NULL,
};
@@ -378,6 +384,8 @@ int glusterBlockCLIOptEnumParse(const char *opt);
int glusterBlockDaemonOptEnumParse(const char *opt);
+int blockLogLevelEnumParse(const char *opt);
+
int blockMetaKeyEnumParse(const char *opt);
int blockMetaStatusEnumParse(const char *opt);