From 32b96d66890a16fd23c8ae065297c7a98097d340 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Sat, 23 Jul 2011 12:16:07 +0200 Subject: cli: add --log-{file,level} options Apart from diagnostic purposes, it's needed when cli is ran by unprivileged user who most likely has no write access to the canonical log file. Change-Id: Ib9d1a31711966ff1efe2592fbc0a911820cf8ee3 BUG: 3242 Reviewed-on: http://review.gluster.com/95 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- cli/src/cli.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'cli/src/cli.c') diff --git a/cli/src/cli.c b/cli/src/cli.c index 50a6c1853..932869038 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -199,27 +199,21 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) static int -logging_init (glusterfs_ctx_t *ctx) +logging_init (struct cli_state *state) { - int ret = 0; - cmd_args_t *cmd_args = NULL; + char *log_file = state->log_file ? state->log_file : + DEFAULT_CLI_LOG_FILE_DIRECTORY "/cli.log"; - cmd_args = &ctx->cmd_args; - - /* CLI should not have something to DEBUG after the release, - hence defaulting to INFO loglevel */ - cmd_args->log_level = GF_LOG_INFO; - - ret = gf_asprintf (&cmd_args->log_file, - DEFAULT_CLI_LOG_FILE_DIRECTORY "/cli.log"); - - if (gf_log_init (cmd_args->log_file) == -1) { + if (gf_log_init (log_file) == -1) { fprintf (stderr, "ERROR: failed to open logfile %s\n", - cmd_args->log_file); + log_file); return -1; } - gf_log_set_loglevel (cmd_args->log_level); + /* CLI should not have something to DEBUG after the release, + hence defaulting to INFO loglevel */ + gf_log_set_loglevel ((state->log_level == -1) ? GF_LOG_INFO : + state->log_level); return 0; } @@ -350,6 +344,20 @@ cli_opt_parse (char *opt, struct cli_state *state) return 0; } + oarg = strtail (opt, "log-file="); + if (oarg) { + state->log_file = oarg; + return 0; + } + + oarg = strtail (opt, "log-level="); + if (oarg) { + state->log_level = glusterd_check_log_level(oarg); + if (state->log_level == -1) + return -1; + return 0; + } + return -1; } @@ -405,6 +413,7 @@ cli_state_init (struct cli_state *state) state->remote_host = "localhost"; + state->log_level = -1; tree = &state->tree; tree->state = state; @@ -618,7 +627,7 @@ main (int argc, char *argv[]) if (ret) goto out; - ret = logging_init (ctx); + ret = logging_init (&state); if (ret) goto out; -- cgit