From 3b95635b50ef30e33f9acb1d2575f9ce490fd852 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 26 Mar 2015 15:01:57 -0400 Subject: [PATCH] configure logging before parsing arguments Signed-off-by: Alfredo Deza --- radosgw_agent/cli.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/radosgw_agent/cli.py b/radosgw_agent/cli.py index 75ea1f2..fa736ce 100644 --- a/radosgw_agent/cli.py +++ b/radosgw_agent/cli.py @@ -313,8 +313,6 @@ def set_args_to_config(args): @catches((KeyboardInterrupt, RuntimeError, AgentError,), handle_all=True) def main(): - args = parse_args() - # root (a.k.a. 'parent') and agent loggers root_logger = logging.getLogger() @@ -323,18 +321,19 @@ def main(): # Console handler, meant only for user-facing information console_loglevel = logging.INFO - if args.verbose: - console_loglevel = logging.DEBUG - elif args.quiet: - console_loglevel = logging.WARN sh = logging.StreamHandler() sh.setFormatter(util.log.color_format()) + # this console level set here before reading options from the arguments + # so that we can get errors if they pop up before sh.setLevel(console_loglevel) agent_logger = logging.getLogger('radosgw_agent') agent_logger.addHandler(sh) + # After initial logging is configured, now parse args + args = parse_args() + # File handler log_file = args.log_file or 'radosgw-agent.log' try: @@ -351,6 +350,15 @@ def main(): root_logger.addHandler(fh) + if args.verbose: + console_loglevel = logging.DEBUG + elif args.quiet: + console_loglevel = logging.WARN + + # now that we have parsed the actual log level we need + # reset it in the handler + sh.setLevel(console_loglevel) + # after loggin is set ensure that the arguments are present in the # config object set_args_to_config(args) -- 2.47.3