Skip to content

Commit 7198586

Browse files
base logging setup
1 parent 8d11a12 commit 7198586

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/eligibility_signposting_api/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
from mangum.types import LambdaContext, LambdaEvent
99

1010
from eligibility_signposting_api import repos, services
11-
from eligibility_signposting_api.config import LOG_LEVEL, config, init_logging
11+
from eligibility_signposting_api.config import LOG_LEVEL, config, setup_logging
1212
from eligibility_signposting_api.error_handler import handle_exception
1313
from eligibility_signposting_api.views.eligibility import eligibility
1414
from eligibility_signposting_api.views.hello import hello
1515

16+
setup_logging()
17+
logger = logging.getLogger(__name__)
1618

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

2830

2931
def create_app() -> Flask:
30-
init_logging()
3132

3233
app = Flask(__name__)
33-
app.logger.info("app created")
34+
logger.info("app created")
3435

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

44-
app.logger.info("app ready")
45+
logger.info("app ready")
4546
return app
4647

4748

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import os
3-
from logging.config import dictConfig
43
from typing import Any, NewType
54

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

2322

24-
def init_logging() -> None:
25-
level = logging.getLevelName(LOG_LEVEL)
23+
def setup_logging():
2624
log_format = "%(asctime)s %(levelname)-8s %(name)s %(module)s.py:%(funcName)s():%(lineno)d %(message)s"
27-
dictConfig(
28-
{
29-
"version": 1,
30-
"formatters": {
31-
"default": {
32-
"format": log_format,
33-
}
34-
},
35-
"handlers": {
36-
"wsgi": {"class": "logging.StreamHandler", "stream": "ext://sys.stdout", "formatter": "default"}
37-
},
38-
"root": {"level": level, "handlers": ["wsgi"]},
39-
"loggers": {
40-
"eligibility_signposting_api.app": {"level": level, "handlers": ["wsgi"], "propagate": False},
41-
},
42-
}
25+
# Define the root logger configuration
26+
logging.basicConfig(
27+
level=logging.DEBUG,
28+
format=log_format,
29+
handlers=[
30+
logging.StreamHandler()
31+
]
4332
)

0 commit comments

Comments
 (0)