Skip to content

Commit

Permalink
Add code to load logging configuration from a file specified in envir…
Browse files Browse the repository at this point in the history
…onment variable
  • Loading branch information
ehclark committed Oct 22, 2024
1 parent 0806b64 commit 49fb067
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/anyvar/restapi/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Provide core route definitions for REST service."""

import logging
import logging.config
import os
import pathlib
import tempfile
from contextlib import asynccontextmanager
from http import HTTPStatus

import ga4gh.vrs
import yaml
from fastapi import Body, FastAPI, File, HTTPException, Path, Query, Request, UploadFile
from fastapi.responses import FileResponse
from pydantic import StrictStr
Expand All @@ -31,6 +35,15 @@
)
from anyvar.utils.types import VrsVariation, variation_class_map

logging_config_file = os.environ.get("ANYVAR_LOGGING_CONFIG", None)
if logging_config_file and pathlib.Path(logging_config_file).is_file():
with pathlib.Path(logging_config_file).open() as fd:
try:
config = yaml.safe_load(fd.read())
logging.config.dictConfig(config)
except Exception:
logging.exception("Error in Logging Configuration. Using default configs")

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -264,6 +277,7 @@ async def annotate_vcf(
_logger.error("Encountered error during VCF registration: %s", e)
return {"error": "Encountered ValueError when registering VCF"}
if not allow_async_write:
_logger.info("Waiting for object store writes from API handler method")
av.object_store.wait_for_writes()
return FileResponse(temp_out_file.name)

Expand Down

0 comments on commit 49fb067

Please sign in to comment.