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
|
- --timeout/-T: Websocket timeout
|
||||||
- --version/-v: Print the obsws-cli version
|
- --version/-v: Print the obsws-cli version
|
||||||
- --loglevel/-l: Set the application's logging level
|
- --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:
|
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):
|
def setup_logging(loglevel: str):
|
||||||
"""Set up logging for the application."""
|
"""Set up logging for the application."""
|
||||||
numeric_loglevel = logging.getLevelNamesMapping().get(loglevel.upper())
|
level_map = logging.getLevelNamesMapping()
|
||||||
if numeric_loglevel is None:
|
try:
|
||||||
raise typer.BadParameter(
|
level_int = level_map[loglevel.upper()]
|
||||||
f'Invalid log level: {loglevel}. Valid options are: {", ".join(logging.getLevelNamesMapping().keys())}'
|
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(
|
logging.basicConfig(
|
||||||
level=numeric_loglevel,
|
level=level_int,
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user