mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2026-02-16 09:57:49 +00:00
upd set_logging for improved readability
This commit is contained in:
parent
71d4a81855
commit
998e72f43e
@ -50,7 +50,7 @@ The CLI should now be discoverable as `obsws-cli`
|
||||
- --timeout/-T: Websocket timeout
|
||||
- --version/-v: Print the obsws-cli version
|
||||
- --loglevel/-l: Set the application's logging level
|
||||
- One of *CRITICAL, FATAL, ERROR, WARNING, INFO, DEBUG*
|
||||
- One of *NOTSET, DEBUG, INFO, WARN, WARNING, ERROR, CRITICAL, FATAL*
|
||||
|
||||
Pass `--host`, `--port` and `--password` as flags on the root command, for example:
|
||||
|
||||
|
||||
@ -30,13 +30,19 @@ def version_callback(value: bool):
|
||||
|
||||
def setup_logging(loglevel: str):
|
||||
"""Set up logging for the application."""
|
||||
numeric_loglevel = logging.getLevelNamesMapping().get(loglevel.upper())
|
||||
if numeric_loglevel is None:
|
||||
raise typer.BadParameter(
|
||||
f'Invalid log level: {loglevel}. Valid options are: {", ".join(logging.getLevelNamesMapping().keys())}'
|
||||
level_map = logging.getLevelNamesMapping()
|
||||
try:
|
||||
level_int = level_map[loglevel.upper()]
|
||||
except KeyError:
|
||||
possible_levels = ', '.join(
|
||||
sorted(level_map.keys(), key=lambda k: level_map[k])
|
||||
)
|
||||
raise typer.BadParameter(
|
||||
f'Invalid log level: {loglevel}. Valid options are: {possible_levels}'
|
||||
) from None
|
||||
|
||||
logging.basicConfig(
|
||||
level=numeric_loglevel,
|
||||
level=level_int,
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user