X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_webhook_translator%2Fsrc%2Fosm_webhook_translator%2Fmain.py;h=7c4404c5c0ba28db1e31129da13c4253bdf62f69;hb=02f71cdb75526c9adec2867c0d832b74f84c2f17;hp=587fa9c48c662d6948a7e98873ab5c3996590bd8;hpb=2e2dca0ad0f237ab5e30c77beee3d20a2a0a7dd0;p=osm%2FNG-SA.git diff --git a/osm_webhook_translator/src/osm_webhook_translator/main.py b/osm_webhook_translator/src/osm_webhook_translator/main.py index 587fa9c..7c4404c 100644 --- a/osm_webhook_translator/src/osm_webhook_translator/main.py +++ b/osm_webhook_translator/src/osm_webhook_translator/main.py @@ -15,6 +15,7 @@ # limitations under the License. ####################################################################################### from datetime import datetime +import logging import os from random import randint @@ -22,6 +23,12 @@ from fastapi import FastAPI import requests +logging.basicConfig( + format="%(asctime)s %(levelname)s %(filename)s:%(lineno)s %(message)s", + datefmt="%Y/%m/%d %H:%M:%S", +) +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) app = FastAPI() @@ -37,17 +44,17 @@ def send_to_airflow(output_endpoint, content): rnd = str(randint(0, 999999)).rjust(6, "0") timestamp = datetime.now().strftime("%Y%m%d%H%M%S") dag_run_id = output_endpoint + "_" + timestamp + "_" + rnd - print(f"HTTP POST {url}...") + logger.info(f"HTTP POST {url}") req = requests.post( url=url, auth=(airflow_user, airflow_pass), json={"dag_run_id": dag_run_id, "conf": content}, ) - print(req.text) + logger.info(f"Response: {req.text}") # timeout and retries except Exception as e: - print(f"HTTP error: {repr(e)}") - raise requests.HTTPException(status_code=403, detail=repr(e)) + logger.error(f"HTTP error: {repr(e)}") + raise requests.HTTPError(status_code=403, detail=repr(e)) @app.post("/{input_endpoint}")