mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-23 07:57:39 +00:00
30 lines
765 B
Python
30 lines
765 B
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
import socket
|
|
|
|
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(
|
|
host=socket.gethostname(),
|
|
name=record.name,
|
|
level=record.levelno,
|
|
message=record.getMessage(),
|
|
traceback=traceback,
|
|
)
|
|
except Error as e:
|
|
print(e)
|