From: Alfredo Deza Date: Thu, 26 Mar 2015 19:01:57 +0000 (-0400) Subject: configure logging before parsing arguments X-Git-Tag: v1.2.2~5^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F26%2Fhead;p=radosgw-agent.git configure logging before parsing arguments Signed-off-by: Alfredo Deza --- 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)