Update app/services/api_logger.py
Browse files- app/services/api_logger.py +14 -11
app/services/api_logger.py
CHANGED
|
@@ -7,6 +7,8 @@ from zoneinfo import ZoneInfo
|
|
| 7 |
|
| 8 |
from motor.motor_asyncio import AsyncIOMotorCollection
|
| 9 |
|
|
|
|
|
|
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
|
|
@@ -33,18 +35,19 @@ class ApiLogger:
|
|
| 33 |
user_id: Optional[str],
|
| 34 |
error_message: Optional[str] = None,
|
| 35 |
) -> None:
|
| 36 |
-
doc = {
|
| 37 |
-
"name": name,
|
| 38 |
-
"status": status,
|
| 39 |
-
"date": self._current_ist_timestamp(),
|
| 40 |
-
"response_time": round(response_time, 3),
|
| 41 |
-
}
|
| 42 |
-
if user_id:
|
| 43 |
-
doc["user_id"] = user_id
|
| 44 |
-
if error_message:
|
| 45 |
-
doc["error_message"] = error_message
|
| 46 |
-
|
| 47 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
await self._collection().insert_one(doc)
|
| 49 |
except Exception:
|
| 50 |
logger.exception("Failed to write categorize API log")
|
|
|
|
| 7 |
|
| 8 |
from motor.motor_asyncio import AsyncIOMotorCollection
|
| 9 |
|
| 10 |
+
from app.db.mongo import connect_to_mongo
|
| 11 |
+
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
|
|
|
|
| 35 |
user_id: Optional[str],
|
| 36 |
error_message: Optional[str] = None,
|
| 37 |
) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
try:
|
| 39 |
+
await connect_to_mongo()
|
| 40 |
+
doc = {
|
| 41 |
+
"name": name,
|
| 42 |
+
"status": status,
|
| 43 |
+
"date": self._current_ist_timestamp(),
|
| 44 |
+
"response_time": round(response_time, 3),
|
| 45 |
+
}
|
| 46 |
+
if user_id:
|
| 47 |
+
doc["user_id"] = user_id
|
| 48 |
+
if error_message:
|
| 49 |
+
doc["error_message"] = error_message
|
| 50 |
+
|
| 51 |
await self._collection().insert_one(doc)
|
| 52 |
except Exception:
|
| 53 |
logger.exception("Failed to write categorize API log")
|