Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/eligibility_signposting_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
from mangum.types import LambdaContext, LambdaEvent

from eligibility_signposting_api import repos, services
from eligibility_signposting_api.config import LOG_LEVEL, config, init_logging
from eligibility_signposting_api.config import LOG_LEVEL, config, setup_logging
from eligibility_signposting_api.error_handler import handle_exception
from eligibility_signposting_api.views.eligibility import eligibility
from eligibility_signposting_api.views.hello import hello

setup_logging()
logger = logging.getLogger(__name__)

def main() -> None: # pragma: no cover
"""Run the Flask app as a local process."""
Expand All @@ -27,10 +29,9 @@ def lambda_handler(event: LambdaEvent, context: LambdaContext) -> dict[str, Any]


def create_app() -> Flask:
init_logging()

app = Flask(__name__)
app.logger.info("app created")
logger.info("app created")

# Register views & error handler
app.register_blueprint(eligibility, url_prefix="/eligibility")
Expand All @@ -41,7 +42,7 @@ def create_app() -> Flask:
container = wireup.create_container(service_modules=[services, repos], parameters=config())
wireup.integration.flask.setup(container, app, import_flask_config=True)

app.logger.info("app ready")
logger.info("app ready")
return app


Expand Down
27 changes: 8 additions & 19 deletions src/eligibility_signposting_api/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
from logging.config import dictConfig
from typing import Any, NewType

from yarl import URL
Expand All @@ -21,23 +20,13 @@ def config() -> dict[str, Any]:
}


def init_logging() -> None:
level = logging.getLevelName(LOG_LEVEL)
def setup_logging():
log_format = "%(asctime)s %(levelname)-8s %(name)s %(module)s.py:%(funcName)s():%(lineno)d %(message)s"
dictConfig(
{
"version": 1,
"formatters": {
"default": {
"format": log_format,
}
},
"handlers": {
"wsgi": {"class": "logging.StreamHandler", "stream": "ext://sys.stdout", "formatter": "default"}
},
"root": {"level": level, "handlers": ["wsgi"]},
"loggers": {
"eligibility_signposting_api.app": {"level": level, "handlers": ["wsgi"], "propagate": False},
},
}
# Define the root logger configuration
logging.basicConfig(
level=logging.DEBUG,
format=log_format,
handlers=[
logging.StreamHandler()
]
)