From b535c44fdd2b71c50a8fcbcf1e1e1c2d1c0340e9 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 17 Aug 2017 11:21:11 +0530 Subject: logger: support logdir choosing via Environment variable Currently the default logdir is DATADIR /log/gluster-block/ This patch will provide a way to change this default logdir via Env variable $ export GB_LOGDIR=/var/log/gluster-block-new-path/ Note: make sure to restart the processes (cli & daemon) after you set GB_LOGDIR Change-Id: Id142e4a4dfe7b6ebc9cf8296b8ceb8bff37691b8 Signed-off-by: Prasanna Kumar Kalever --- daemon/gluster-blockd.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'daemon') diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c index 02ed642..c96e4bd 100644 --- a/daemon/gluster-blockd.c +++ b/daemon/gluster-blockd.c @@ -50,30 +50,6 @@ glusterBlockDHelp(void) } -static bool -glusterBlockLogdirCreate(void) -{ - DIR* dir = opendir(GB_LOGDIR); - - - if (dir) { - closedir(dir); - } else if (errno == ENOENT) { - if (mkdir(GB_LOGDIR, 0755) == -1) { - LOG("mgmt", GB_LOG_ERROR, "mkdir(%s) failed (%s)", - GB_LOGDIR, strerror (errno)); - return FALSE; - } - } else { - LOG("mgmt", GB_LOG_ERROR, "opendir(%s) failed (%s)", - GB_LOGDIR, strerror (errno)); - return FALSE; - } - - return TRUE; -} - - void * glusterBlockCliThreadProc (void *vargp) { @@ -266,8 +242,8 @@ glusterBlockDParseArgs(int count, char **options) MSG("option '%s' needs argument \n", options[optind-1]); return -1; } - logLevel = blockLogLevelEnumParse(options[optind]); - if (logLevel >= GB_LOG_MAX) { + gbConf.logLevel = blockLogLevelEnumParse(options[optind]); + if (gbConf.logLevel >= GB_LOG_MAX) { MSG("unknown LOG-LEVEL: '%s'\n", options[optind]); return -1; } @@ -291,12 +267,12 @@ main (int argc, char **argv) int errnosv = 0; - if (glusterBlockDParseArgs(argc, argv)) { - LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockDParseArgs() failed"); - return -1; + if(initLogging()) { + exit(EXIT_FAILURE); } - if (!glusterBlockLogdirCreate()) { + if (glusterBlockDParseArgs(argc, argv)) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockDParseArgs() failed"); return -1; } -- cgit