Skip to content

Commit

Permalink
added logger in the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachinbisht27 committed Apr 15, 2024
1 parent a42c908 commit 94f9f2f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ENVIRONMENT=
DB_USER=
DB_PASSWORD=
DB_NAME=
Expand Down
7 changes: 5 additions & 2 deletions app/services/webhook_transaction_log_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from app.helpers import db
from app import models
from app.utils.loggingutils import logger


class WebhookTransactionLogService:
Expand All @@ -16,7 +17,7 @@ def create_new_webhook_log(self, jsonData):
db.commit()
return new_webhook_log
except Exception as e:
print(
logger.error(
f"Error while creating new webhook log. Webhook: {jsonData}. Error message: {e}"
)
finally:
Expand All @@ -28,6 +29,8 @@ def mark_webhook_log_as_processed(self, webhook_log):
db.add(webhook_log)
db.commit()
except Exception as e:
print(f"Error while marking webhook log as processed. Error message: {e}")
logger.error(
f"Error while marking webhook log as processed. Error message: {e}"
)
finally:
db.close()
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

load_dotenv()

ENVIRONMENT = os.environ.get("ENVIRONMENT", "development")

# Database configuration
POSTGRES = {
"user": os.getenv("DB_USER"),
Expand Down
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI
from agraffe import Agraffe
from app.services import WebhookTransactionLogService
from app.utils.loggingutils import logger

app = FastAPI()

Expand All @@ -12,7 +13,9 @@ def handle_payload(request):
if jsonData:
handle_webhook(jsonData)
except Exception as e:
print(f"Error: {e}")
logger.error(
f"Exception occured while handling the webhook payload: {jsonData}. Error: {e}"
)
return jsonData
else:
return "System does not accepts GET request"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ sqlalchemy==1.4.26
uvicorn==0.15.0
setuptools==69.2.0
python-dotenv==1.0.1
google-cloud-logging==3.10.0

0 comments on commit 94f9f2f

Please sign in to comment.