blob: f133832aa1767b01c9bc447a7e76aa76c09d4ea8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
from logging import LogRecord, StreamHandler
class DatabaseLogHandler(StreamHandler):
"""Logs entries into the database."""
def emit(self, record: LogRecord):
"""Write the given `record` into the database."""
# This import needs to be deferred due to Django's application
# registry instantiation logic loading this handler before the
# application is ready.
from pydis_site.apps.api.models.log_entry import LogEntry
entry = LogEntry(
application='site',
logger_name=record.name,
level=record.levelname.lower(),
module=record.module,
line=record.lineno,
message=self.format(record)
)
entry.save()
|