allow lowercase log level name
This commit is contained in:
parent
f70349716a
commit
f64bd68f6f
@ -25,9 +25,7 @@ from compute.utils import ids
|
|||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
log_levels = logging.getLevelNamesMapping()
|
log_levels = [lv.lower() for lv in logging.getLevelNamesMapping()]
|
||||||
|
|
||||||
env_log_level = os.getenv('CMP_LOG')
|
|
||||||
|
|
||||||
libvirt.registerErrorHandler(
|
libvirt.registerErrorHandler(
|
||||||
lambda userdata, err: None, # noqa: ARG005
|
lambda userdata, err: None, # noqa: ARG005
|
||||||
@ -253,6 +251,7 @@ def cli() -> None: # noqa: PLR0915
|
|||||||
root.add_argument(
|
root.add_argument(
|
||||||
'-l',
|
'-l',
|
||||||
'--log-level',
|
'--log-level',
|
||||||
|
type=str.lower,
|
||||||
metavar='LEVEL',
|
metavar='LEVEL',
|
||||||
choices=log_levels,
|
choices=log_levels,
|
||||||
help='log level [envvar: CMP_LOG]',
|
help='log level [envvar: CMP_LOG]',
|
||||||
@ -369,9 +368,12 @@ def cli() -> None: # noqa: PLR0915
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Set logging level
|
# Set logging level
|
||||||
log_level = args.log_level or env_log_level
|
log_level = args.log_level or os.getenv('CMP_LOG')
|
||||||
if log_level in log_levels:
|
|
||||||
logging.basicConfig(level=log_levels[log_level])
|
if isinstance(log_level, str) and log_level.lower() in log_levels:
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.getLevelNamesMapping()[log_level.upper()]
|
||||||
|
)
|
||||||
|
|
||||||
log.debug('CLI started with args: %s', args)
|
log.debug('CLI started with args: %s', args)
|
||||||
# Perform actions
|
# Perform actions
|
||||||
|
Loading…
Reference in New Issue
Block a user