2016-02-27 20:18:50 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
|
|
|
2020-11-02 18:54:27 +01:00
|
|
|
class PaperlessHandler(logging.Handler):
|
2016-02-27 20:18:50 +00:00
|
|
|
def emit(self, record):
|
|
|
|
|
# We have to do the import here or Django will barf when it tries to
|
|
|
|
|
# load this because the apps aren't loaded at that point
|
|
|
|
|
from .models import Log
|
|
|
|
|
|
2016-03-28 11:11:15 +01:00
|
|
|
kwargs = {"message": record.msg, "level": record.levelno}
|
2016-02-27 20:18:50 +00:00
|
|
|
|
|
|
|
|
if hasattr(record, "group"):
|
|
|
|
|
kwargs["group"] = record.group
|
|
|
|
|
|
|
|
|
|
Log.objects.create(**kwargs)
|