Skip to content

Commit d17b355

Browse files
committed
efs
1 parent 24e9898 commit d17b355

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

services/efs-guardian/src/simcore_service_efs_guardian/core/application.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
def create_app(settings: ApplicationSettings | None = None) -> FastAPI:
3232
app_settings = settings or ApplicationSettings.create_from_envs()
3333

34-
logger.info("app settings: %s", app_settings.model_dump_json(indent=1))
35-
3634
app = FastAPI(
3735
debug=app_settings.EFS_GUARDIAN_DEBUG,
3836
title=APP_NAME,
Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
"""Main application to be deployed by uvicorn (or equivalent) server"""
22

3+
import logging
4+
from typing import Final
5+
6+
from common_library.json_serialization import json_dumps
37
from fastapi import FastAPI
4-
from servicelib.logging_utils import setup_loggers
8+
from servicelib.fastapi.logging_lifespan import setup_logging_shutdown_event
59
from simcore_service_efs_guardian.core.application import create_app
610
from simcore_service_efs_guardian.core.settings import ApplicationSettings
711

8-
the_settings = ApplicationSettings.create_from_envs()
9-
setup_loggers(
10-
log_format_local_dev_enabled=the_settings.EFS_GUARDIAN_LOG_FORMAT_LOCAL_DEV_ENABLED,
11-
logger_filter_mapping=the_settings.EFS_GUARDIAN_LOG_FILTER_MAPPING,
12-
tracing_settings=the_settings.EFS_GUARDIAN_TRACING,
13-
log_base_level=the_settings.log_level,
14-
noisy_loggers=None,
12+
_logger = logging.getLogger(__name__)
13+
14+
_NOISY_LOGGERS: Final[tuple[str, ...]] = (
15+
"aiobotocore",
16+
"aio_pika",
17+
"aiormq",
18+
"botocore",
19+
"werkzeug",
1520
)
1621

17-
# SINGLETON FastAPI app
18-
the_app: FastAPI = create_app(the_settings)
22+
23+
def app_factory() -> FastAPI:
24+
app_settings = ApplicationSettings.create_from_envs()
25+
logging_shutdown_event = setup_logging_shutdown_event(
26+
log_format_local_dev_enabled=app_settings.EFS_GUARDIAN_LOG_FORMAT_LOCAL_DEV_ENABLED,
27+
logger_filter_mapping=app_settings.EFS_GUARDIAN_LOG_FILTER_MAPPING,
28+
tracing_settings=app_settings.EFS_GUARDIAN_TRACING,
29+
log_base_level=app_settings.log_level,
30+
noisy_loggers=_NOISY_LOGGERS,
31+
)
32+
33+
_logger.info(
34+
"Application settings: %s",
35+
json_dumps(app_settings, indent=2, sort_keys=True),
36+
)
37+
app = create_app(settings=app_settings)
38+
app.add_event_handler("shutdown", logging_shutdown_event)
39+
return app

0 commit comments

Comments
 (0)