0
0
Fork 0
mirror of https://github.com/healthchecks/healthchecks.git synced 2025-04-11 07:41:19 +00:00
healthchecks_healthchecks/hc/logs/__init__.py

27 lines
708 B
Python

from __future__ import annotations
import logging
from django.db import Error
FORMATTER = logging.Formatter()
class Handler(logging.Handler):
def emit(self, record: logging.LogRecord) -> None:
# Import Record now not earlier, to avoid AppRegistryNotReady exception
from hc.logs.models import Record
traceback = ""
if record.exc_info:
traceback = FORMATTER.formatException(record.exc_info)
try:
Record.objects.create(
name=record.name,
level=record.levelno,
message=record.getMessage(),
traceback=traceback,
)
except Error as e:
print(e)