def setup_logging(config_path, config_opts, options):
log_ini = os.path.join(config_path, config_opts["log_config_file"])
try:
if not os.path.exists(log_ini):
if os.path.normpath('/etc/mock') != os.path.normpath(config_path):
log.warning("Could not find required logging config file: %s. Using default...",
log_ini)
log_ini = os.path.join("/etc/mock", config_opts["log_config_file"])
if not os.path.exists(log_ini):
raise IOError("Could not find log config file %s" % log_ini)
else:
raise IOError("Could not find log config file %s" % log_ini)
except IOError as exc:
log.error(exc)
sys.exit(50)
try:
log_cfg = configparser.ConfigParser()
logging.config.fileConfig(log_ini)
log_cfg.read(log_ini)
except (IOError, OSError, configparser.NoSectionError) as exc:
log.error("Log config file(%s) not correctly configured: %s", log_ini, exc)
sys.exit(50)
try:
# set up logging format strings
config_opts['build_log_fmt_str'] = log_cfg.get("formatter_%s" % config_opts['build_log_fmt_name'],
"format", raw=1)
config_opts['root_log_fmt_str'] = log_cfg.get("formatter_%s" % config_opts['root_log_fmt_name'],
"format", raw=1)
config_opts['state_log_fmt_str'] = log_cfg.get("formatter_%s" % config_opts['state_log_fmt_name'],
"format", raw=1)
except configparser.NoSectionError as exc:
log.error("Log config file (%s) missing required section: %s", log_ini, exc)
sys.exit(50)
# set logging verbosity
if options.verbose == 0:
log.handlers[0].setLevel(logging.WARNING)
tmplog = logging.getLogger("mockbuild.Root.state")
if tmplog.handlers:
tmplog.handlers[0].setLevel(logging.WARNING)
elif options.verbose == 1:
log.handlers[0].setLevel(logging.INFO)
elif options.verbose == 2:
log.handlers[0].setLevel(logging.DEBUG)
logging.getLogger("mockbuild.Root.build").propagate = 1
logging.getLogger("mockbuild").propagate = 1
# enable tracing if requested
logging.getLogger("trace").propagate = 0
if options.trace:
logging.getLogger("trace").propagate = 1
评论列表
文章目录