|
1 | 1 | """Main application to be deployed in for example uvicorn.""" |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from typing import Final |
4 | 5 |
|
5 | | -from servicelib.logging_utils import setup_loggers |
| 6 | +from common_library.json_serialization import json_dumps |
| 7 | +from fastapi import FastAPI |
| 8 | +from servicelib.fastapi.logging_lifespan import setup_logging_shutdown_event |
6 | 9 | from simcore_service_storage.core.application import create_app |
7 | 10 | from simcore_service_storage.core.settings import ApplicationSettings |
8 | 11 |
|
| 12 | +_logger = logging.getLogger(__name__) |
| 13 | + |
9 | 14 | _NOISY_LOGGERS: Final[tuple[str, ...]] = ( |
10 | 15 | "aio_pika", |
11 | 16 | "aiobotocore", |
|
16 | 21 | "werkzeug", |
17 | 22 | ) |
18 | 23 |
|
19 | | -_settings = ApplicationSettings.create_from_envs() |
20 | 24 |
|
21 | | -setup_loggers( |
22 | | - log_format_local_dev_enabled=_settings.STORAGE_LOG_FORMAT_LOCAL_DEV_ENABLED, |
23 | | - logger_filter_mapping=_settings.STORAGE_LOG_FILTER_MAPPING, |
24 | | - tracing_settings=_settings.STORAGE_TRACING, |
25 | | - log_base_level=_settings.log_level, |
26 | | - noisy_loggers=_NOISY_LOGGERS, |
27 | | -) |
| 25 | +def app_factory() -> FastAPI: |
| 26 | + app_settings = ApplicationSettings.create_from_envs() |
| 27 | + logging_shutdown_event = setup_logging_shutdown_event( |
| 28 | + log_format_local_dev_enabled=app_settings.STORAGE_LOG_FORMAT_LOCAL_DEV_ENABLED, |
| 29 | + logger_filter_mapping=app_settings.STORAGE_LOG_FILTER_MAPPING, |
| 30 | + tracing_settings=app_settings.STORAGE_TRACING, |
| 31 | + log_base_level=app_settings.log_level, |
| 32 | + noisy_loggers=_NOISY_LOGGERS, |
| 33 | + ) |
28 | 34 |
|
29 | | -app = create_app(_settings) |
| 35 | + _logger.info( |
| 36 | + "Application settings: %s", |
| 37 | + json_dumps(app_settings, indent=2, sort_keys=True), |
| 38 | + ) |
| 39 | + app = create_app(settings=app_settings) |
| 40 | + app.add_event_handler("shutdown", logging_shutdown_event) |
| 41 | + return app |
0 commit comments