feat: logging
This commit is contained in:
20
logger/formatter.py
Normal file
20
logger/formatter.py
Normal file
@ -0,0 +1,20 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user