From 66c581b270bb31c0f95ba5fa31c0d27ba07f3ccb Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 19 Aug 2024 15:02:40 -0700 Subject: [PATCH] Add logging configuration to UWS worker Set up logging during import of the UWS backend worker code using the now-independently-installable safir-logging PyPI package. --- .../example-uws/scripts/install-worker.sh | 3 ++- .../example-uws/src/exampleuws/workers/exampleuws.py | 7 +++++++ .../{{cookiecutter.name}}/scripts/install-worker.sh | 3 ++- .../workers/{{cookiecutter.module_name}}.py | 7 +++++++ project_templates/technote_md/testn-000/technote.toml | 2 +- project_templates/technote_rst/testn-000/technote.toml | 2 +- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/project_templates/fastapi_safir_app/example-uws/scripts/install-worker.sh b/project_templates/fastapi_safir_app/example-uws/scripts/install-worker.sh index 825b9a4c..1838c6e6 100644 --- a/project_templates/fastapi_safir_app/example-uws/scripts/install-worker.sh +++ b/project_templates/fastapi_safir_app/example-uws/scripts/install-worker.sh @@ -23,5 +23,6 @@ set -x # required by the remote Butler client, and google-cloud-storage is used to # store cutouts when the bucket has a gs URL. cd "$1" -pip install --no-cache-dir google-cloud-storage httpx safir-arq structlog +pip install --no-cache-dir \ + google-cloud-storage httpx safir-arq safir-logging structlog pip install --no-cache-dir --no-deps . diff --git a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/workers/exampleuws.py b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/workers/exampleuws.py index ff8f0d26..02a36753 100644 --- a/project_templates/fastapi_safir_app/example-uws/src/exampleuws/workers/exampleuws.py +++ b/project_templates/fastapi_safir_app/example-uws/src/exampleuws/workers/exampleuws.py @@ -18,6 +18,7 @@ WorkerResult, build_worker, ) +from safir.logging import configure_logging from structlog.stdlib import BoundLogger from ..domain import WorkerExampleuwsModel @@ -80,6 +81,12 @@ def example_uws( ] +configure_logging( + name="exampleuws", + profile=os.getenv("EXAMPLE_UWS_PROFILE", "development"), + log_level=os.getenv("EXAMPLE_UWS_LOG_LEVEL", "INFO"), +) + WorkerSettings = build_worker( example_uws, WorkerConfig( diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/scripts/install-worker.sh b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/scripts/install-worker.sh index 9796d81b..a4efe17d 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/scripts/install-worker.sh +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/scripts/install-worker.sh @@ -23,6 +23,7 @@ set -x # required by the remote Butler client, and google-cloud-storage is used to # store cutouts when the bucket has a gs URL. cd "$1" -pip install --no-cache-dir google-cloud-storage httpx safir-arq structlog +pip install --no-cache-dir \ + google-cloud-storage httpx safir-arq safir-logging structlog pip install --no-cache-dir --no-deps . {%- endif %} diff --git a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/workers/{{cookiecutter.module_name}}.py b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/workers/{{cookiecutter.module_name}}.py index 0538c74e..f07def56 100644 --- a/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/workers/{{cookiecutter.module_name}}.py +++ b/project_templates/fastapi_safir_app/{{cookiecutter.name}}/src/{{cookiecutter.module_name}}/workers/{{cookiecutter.module_name}}.py @@ -19,6 +19,7 @@ WorkerResult, build_worker, ) +from safir.logging import configure_logging from structlog.stdlib import BoundLogger from ..domain import Worker{{ cookiecutter.module_name | capitalize }}Model @@ -81,6 +82,12 @@ def {{ cookiecutter.name | replace('-', '_') }}( ] +configure_logging( + name="{{ cookiecutter.module_name }}", + profile=os.getenv("{{ cookiecutter.name | upper | replace('-', '_') }}_PROFILE", "development"), + log_level=os.getenv("{{ cookiecutter.name | upper | replace('-', '_') }}_LOG_LEVEL", "INFO"), +) + WorkerSettings = build_worker( {{ cookiecutter.name | replace('-', '_') }}, WorkerConfig( diff --git a/project_templates/technote_md/testn-000/technote.toml b/project_templates/technote_md/testn-000/technote.toml index 1a6415d7..8e79478c 100644 --- a/project_templates/technote_md/testn-000/technote.toml +++ b/project_templates/technote_md/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-08-15T18:24:54Z +date_created = 2024-08-19T22:02:27Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0" diff --git a/project_templates/technote_rst/testn-000/technote.toml b/project_templates/technote_rst/testn-000/technote.toml index dc32b056..9cf50630 100644 --- a/project_templates/technote_rst/testn-000/technote.toml +++ b/project_templates/technote_rst/testn-000/technote.toml @@ -4,7 +4,7 @@ series_id = "TESTN" canonical_url = "https://testn-000.lsst.io" github_url = "https://github.com/lsst/testn-000" github_default_branch = "main" -date_created = 2024-08-15T18:24:54Z +date_created = 2024-08-19T22:02:27Z organization.name = "Vera C. Rubin Observatory" organization.ror = "https://ror.org/048g3cy84" license.id = "CC-BY-4.0"