|
13 | 13 |
|
14 | 14 | """ |
15 | 15 |
|
| 16 | +from contextlib import AsyncExitStack |
16 | 17 | import logging |
17 | 18 | import os |
18 | 19 | from typing import Annotated, Final |
|
22 | 23 | from common_library.json_serialization import json_dumps |
23 | 24 | from settings_library.utils_cli import create_settings_command |
24 | 25 |
|
| 26 | +from servicelib.logging_utils import setup_async_loggers |
| 27 | + |
25 | 28 | from .application_settings import ApplicationSettings |
26 | 29 | from .login import cli as login_cli |
27 | 30 |
|
@@ -80,12 +83,26 @@ async def app_factory() -> web.Application: |
80 | 83 | tracing_settings=app_settings.WEBSERVER_TRACING, |
81 | 84 | ) |
82 | 85 |
|
83 | | - if app_settings.WEBSERVER_APP_FACTORY_NAME == "WEBSERVER_AUTHZ_APP_FACTORY": |
| 86 | + exit_stack = AsyncExitStack() |
| 87 | + await exit_stack.enter_async_context( |
| 88 | + setup_async_loggers( |
| 89 | + log_format_local_dev_enabled=app_settings.WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED, |
| 90 | + logger_filter_mapping=app_settings.WEBSERVER_LOG_FILTER_MAPPING, |
| 91 | + tracing_settings=app_settings.WEBSERVER_TRACING, |
| 92 | + ) |
| 93 | + ) |
84 | 94 |
|
| 95 | + if app_settings.WEBSERVER_APP_FACTORY_NAME == "WEBSERVER_AUTHZ_APP_FACTORY": |
85 | 96 | app = create_application_auth() |
86 | 97 | else: |
87 | 98 | app, _ = _setup_app_from_settings(app_settings) |
88 | 99 |
|
| 100 | + async def _cleanup_event(app: web.Application) -> None: |
| 101 | + assert app # nosec |
| 102 | + _logger.info("Cleaning up application resources") |
| 103 | + await exit_stack.aclose() |
| 104 | + |
| 105 | + app.on_cleanup.append(_cleanup_event) |
89 | 106 | return app |
90 | 107 |
|
91 | 108 |
|
|
0 commit comments