Skip to content

Commit 3aca204

Browse files
Karthikeyannhsacerathereinspirative-nhs-nvirTOEL2
authored
[ELI-137] Base Logging config change
* base logging setup * getting log level from env and revoke name change for func logging config * Failing linting should fail the build pipeline. * lint fixes * Linting needs poetry. * Misc/dev setup changes (#26) * Pin localstack image version. * Use http://localstack:4566/ as default endpoint for lambda <-> communication within localstack. * Pin sam/build-python image version. * Formatting fix. * Shorten env var name LOCALSTACK_INTERNAL_DYNAMODB_ENDPOINT * Try to fix sonarqube coverage reporting. (#24) * adding changes --------- Co-authored-by: Simon Brunning <[email protected]> Co-authored-by: TOEL2 <[email protected]>
1 parent 828661a commit 3aca204

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

scripts/tests/lint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
make dependencies install-python lint

src/eligibility_signposting_api/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from eligibility_signposting_api.views.eligibility import eligibility
1414
from eligibility_signposting_api.views.hello import hello
1515

16+
init_logging()
17+
logger = logging.getLogger(__name__)
18+
1619

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

2831

2932
def create_app() -> Flask:
30-
init_logging()
31-
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: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import logging
22
import os
3-
from logging.config import dictConfig
43
from typing import Any, NewType
54

65
from yarl import URL
76

8-
LOG_LEVEL = logging.DEBUG
7+
LOG_LEVEL = logging.getLevelNamesMapping().get(os.getenv("LOG_LEVEL", ""), logging.WARNING)
98

109
AwsRegion = NewType("AwsRegion", str)
1110
AwsAccessKey = NewType("AwsAccessKey", str)
@@ -22,22 +21,5 @@ def config() -> dict[str, Any]:
2221

2322

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

0 commit comments

Comments
 (0)