diff --git a/nebari_workflow_controller/__init__.py b/nebari_workflow_controller/__init__.py index 8dbbe09..617cb9a 100644 --- a/nebari_workflow_controller/__init__.py +++ b/nebari_workflow_controller/__init__.py @@ -1,6 +1,4 @@ -import logging.config - -LOGGING_CONFIG = { +DEFAULT_LOGGING_CONFIG = { "version": 1, "disable_existing_loggers": False, "formatters": { @@ -32,4 +30,3 @@ }, }, } -logging.config.dictConfig(LOGGING_CONFIG) diff --git a/nebari_workflow_controller/__main__.py b/nebari_workflow_controller/__main__.py index b5a2120..96fbf81 100644 --- a/nebari_workflow_controller/__main__.py +++ b/nebari_workflow_controller/__main__.py @@ -1,19 +1,45 @@ +import argparse import logging import uvicorn +from nebari_workflow_controller import DEFAULT_LOGGING_CONFIG as LOGGING_CONFIG + logger = logging.getLogger(__name__) def main(): + args = parse_args() logger.info("Starting nebari_workflow_controller") uvicorn.run( "nebari_workflow_controller.app:app", host="0.0.0.0", port=8080, reload=False, + log_level=args.log_level.lower(), + ) + + +def parse_args(): + """Parse command line arguments.""" + parser = argparse.ArgumentParser(description="Process some integers.") + parser.add_argument( + "-l", + "--log-level", + dest="log_level", + default="INFO", + help="Set the log level (default: INFO)", ) + args = parser.parse_args() + + # Configure logging + LOGGING_CONFIG["loggers"][""]["level"] = args.log_level + LOGGING_CONFIG["loggers"]["nebari_workflow_controller"]["level"] = args.log_level + logging.config.dictConfig(LOGGING_CONFIG) + + return args if __name__ == "__main__": + # If you change these lines, then update nwc.py accordingly main() diff --git a/nebari_workflow_controller/app.py b/nebari_workflow_controller/app.py index 4b0245d..2bec60b 100644 --- a/nebari_workflow_controller/app.py +++ b/nebari_workflow_controller/app.py @@ -33,6 +33,7 @@ @app.post("/validate") def validate(request=Body(...)): + logger.debug(f"Received request: \n\n{request}") return_response = partial( base_return_response, apiVersion=request["apiVersion"], @@ -112,6 +113,7 @@ def validate(request=Body(...)): @app.post("/mutate") def mutate(request=Body(...)): + logger.debug(f"Received request: \n\n{request}") return_response = partial( base_return_response, apiVersion=request["apiVersion"], diff --git a/nwc.py b/nwc.py new file mode 100644 index 0000000..7fc09de --- /dev/null +++ b/nwc.py @@ -0,0 +1,7 @@ +"""This module provides an alias (nwc) for nebari-workflow-controller. +E.g. "python -m nwc" or "python -m nebari_workflow_controller" will start nebari-workflow-controller. +""" +from nebari_workflow_controller.__main__ import main + +if __name__ == "__main__": + main()