Skip to content

Commit

Permalink
logger: logdir path setting via Env variable 'TCMU_LOGDIR'
Browse files Browse the repository at this point in the history
$ export TCMU_LOGDIR="/var/log/mylogdir/"
$ ./tcmu-runner

or

one can pass 'TCMU_LOGDIR' to list of systemd Env variables and
be able to run via systemd unit

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
  • Loading branch information
Prasanna Kumar Kalever authored and Xiubo Li committed Sep 2, 2017
1 parent 5858bb1 commit b49ea62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libtcmu_config.c
Expand Up @@ -156,8 +156,9 @@ static void tcmu_conf_set_options(struct tcmu_config *cfg, bool reloading)
/*
* The priority of the logdir setting is:
* 1, --tcmu_log_dir/-l LOG_DIR_PATH
* 2, tcmu.conf
* 3, default /var/log/
* 2, export TCMU_LOGDIR="/var/log/mychoice/"
* 3, tcmu.conf
* 4, default /var/log/
*/
if (!tcmu_get_logdir())
tcmu_logdir_create(cfg->log_dir_path);
Expand Down
17 changes: 17 additions & 0 deletions libtcmu_log.c
Expand Up @@ -88,6 +88,23 @@ unsigned int tcmu_get_log_level(void)
return tcmu_log_level;
}

bool tcmu_logdir_getenv(void)
{
char *log_path;

if (tcmu_get_logdir())
return true;

log_path = getenv("TCMU_LOGDIR");
if (!log_path)
return true;

if (!tcmu_logdir_create(log_path))
return false;

return true;
}

void tcmu_set_log_level(int level)
{
/* set the default log level to info */
Expand Down
1 change: 1 addition & 0 deletions libtcmu_log.h
Expand Up @@ -63,6 +63,7 @@ void tcmu_dbg_scsi_cmd_message(struct tcmu_device *dev, const char *funcname, in

char *tcmu_get_logdir(void);
void tcmu_logdir_destroy(void);
bool tcmu_logdir_getenv(void);
bool tcmu_logdir_create(const char *path);
int tcmu_make_absolute_logfile(char *path, const char *filename);

Expand Down
3 changes: 3 additions & 0 deletions main.c
Expand Up @@ -955,6 +955,9 @@ int main(int argc, char **argv)
}
}

if (!tcmu_logdir_getenv())
goto free_opt;

/*
* The order of setting up config and logger is important, because
* the log directory may be configured via the system config file
Expand Down

0 comments on commit b49ea62

Please sign in to comment.