Skip to content

Commit

Permalink
add logging, nwc alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-D-Lewis committed May 3, 2023
1 parent d1549d9 commit 112282d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
5 changes: 1 addition & 4 deletions nebari_workflow_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import logging.config

LOGGING_CONFIG = {
DEFAULT_LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
Expand Down Expand Up @@ -32,4 +30,3 @@
},
},
}
logging.config.dictConfig(LOGGING_CONFIG)
26 changes: 26 additions & 0 deletions nebari_workflow_controller/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions nebari_workflow_controller/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
7 changes: 7 additions & 0 deletions nwc.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 112282d

Please sign in to comment.