Files
Crm-Backend/logger/formatter.py
2025-07-28 15:27:17 +04:00

21 lines
572 B
Python

import json
import logging
from datetime import datetime, UTC
class JsonFormatter(logging.Formatter):
def format(self, record: any):
log_record = {
"timestamp": datetime.now(UTC).isoformat(),
"level": record.levelname,
"module": record.module,
"line": record.lineno,
"message": record.getMessage(),
"request_id": record.request_id,
}
if record.exc_info:
log_record["exception"] = self.formatException(record.exc_info)
return json.dumps(log_record)