summaryrefslogtreecommitdiffstats
path: root/cli/src/cli.c
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-07-23 12:16:07 +0200
committerVijay Bellur <vijay@gluster.com>2011-09-12 06:22:32 -0700
commit32b96d66890a16fd23c8ae065297c7a98097d340 (patch)
tree353d7116ceb99624318461d19722580f25b4b824 /cli/src/cli.c
parent3d67836dba4f5a94f33e9ac13b7ebbf01344ac37 (diff)
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 <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'cli/src/cli.c')
-rw-r--r--cli/src/cli.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 50a6c185344..932869038f1 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;