diff --git a/README.md b/README.md index 4e7a478..d9ccb2e 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/obsws_cli/app.py b/obsws_cli/app.py index ea8ddc8..75bf290 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -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', )