21 lines
572 B
Python
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)
|