diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 71c4f06..17dd225 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -28,11 +28,15 @@ def version_callback(value: bool): raise typer.Exit() -def setup_logging(debug: bool): +def setup_logging(loglevel: str): """Set up logging for the application.""" - log_level = logging.DEBUG if debug else logging.CRITICAL + loglevel = loglevel.upper() + if loglevel not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']: + raise typer.BadParameter( + f'Invalid log level: {loglevel}. Choose from DEBUG, INFO, WARNING, ERROR, CRITICAL.' + ) logging.basicConfig( - level=log_level, + level=loglevel, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', ) @@ -121,19 +125,18 @@ def main( callback=version_callback, ), ] = False, - debug: Annotated[ - bool, + loglevel: Annotated[ + str, typer.Option( - '--debug', - '-d', - envvar='OBSWS_CLI_DEBUG', + '--loglevel', + '-l', + envvar='OBSWS_CLI_LOGLEVEL', is_eager=True, - help='Enable debug logging', + help='Set the logging level', show_default=False, callback=setup_logging, - hidden=True, ), - ] = envconfig.get('debug'), + ] = envconfig.get('loglevel'), ): """obsws_cli is a command line interface for the OBS WebSocket API.""" ctx.ensure_object(dict) diff --git a/obsws_cli/envconfig.py b/obsws_cli/envconfig.py index 0be84f4..121acd7 100644 --- a/obsws_cli/envconfig.py +++ b/obsws_cli/envconfig.py @@ -124,7 +124,7 @@ _envconfig = EnvConfig( OBSWS_CLI_PORT=4455, OBSWS_CLI_PASSWORD='', OBSWS_CLI_TIMEOUT=5, - OBSWS_CLI_DEBUG=False, + OBSWS_CLI_LOGLEVEL='WARNING', OBSWS_CLI_STYLE='disabled', OBSWS_CLI_STYLE_NO_BORDER=False, )