Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 4 additions & 3 deletions src/eligibility_signposting_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from eligibility_signposting_api.views.eligibility import eligibility
from eligibility_signposting_api.views.hello import hello

init_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
26 changes: 7 additions & 19 deletions src/eligibility_signposting_api/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
import os
from logging.config import dictConfig
from typing import Any, NewType

from yarl import URL

LOG_LEVEL = logging.DEBUG
LOG_LEVEL = logging.getLevelNamesMapping().get(os.getenv("LOG_LEVEL", None), logging.WARNING)

AwsRegion = NewType("AwsRegion", str)
AwsAccessKey = NewType("AwsAccessKey", str)
Expand All @@ -22,22 +21,11 @@ def config() -> dict[str, Any]:


def init_logging() -> None:
level = logging.getLevelName(LOG_LEVEL)
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},
},
}
logging.basicConfig(
level=LOG_LEVEL,
format=log_format,
handlers=[
logging.StreamHandler()
]
)