From 8f7126b4650d9cdb6c5cc9b711bb0c397ecbce12 Mon Sep 17 00:00:00 2001 From: Luis Helder Date: Fri, 5 Apr 2024 18:03:55 -0300 Subject: [PATCH] chore: add logs --- gateways/clients/s3_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gateways/clients/s3_client.py b/gateways/clients/s3_client.py index 8eb88a2..702f4ba 100644 --- a/gateways/clients/s3_client.py +++ b/gateways/clients/s3_client.py @@ -3,13 +3,17 @@ from boto3.session import Session from common.configuration import S3_ENDPOINT +from common.logging import get_logger +logger = get_logger() + class S3Client: """This is an abstraction for boto3 s3 client""" def __init__(self) -> None: session = Session() + self.log = logger.new() if S3_ENDPOINT is None: self.client = session.client("s3") else: @@ -29,8 +33,11 @@ def load_file(self, bucket: str, file: str) -> Union[str, None]: response = self.client.get_object(Bucket=bucket, Key=file) return response["Body"].read().decode() except self.client.exceptions.NoSuchKey: - # TODO: Add log here + self.log.error("File not found in s3", bucket=bucket, file=file) return None + except Exception as e: + self.log.error("Error loading file from s3", error=str(e)) + raise e def upload_file(self, bucket: str, file: str, content: str) -> dict: """Writes a string to a file in the storage.