mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-11 09:07:18 +01:00
New logging appears to work
This commit is contained in:
parent
e149baec4e
commit
2fe9b0cbc1
16 changed files with 346 additions and 188 deletions
30
src/documents/loggers.py
Normal file
30
src/documents/loggers.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import logging
|
||||
|
||||
|
||||
class PaperlessLogger(logging.StreamHandler):
|
||||
"""
|
||||
A logger smart enough to know to log some kinds of messages to the database
|
||||
for later retrieval in a pretty interface.
|
||||
"""
|
||||
|
||||
def emit(self, record):
|
||||
|
||||
logging.StreamHandler.emit(self, record)
|
||||
|
||||
if not hasattr(record, "component"):
|
||||
return
|
||||
|
||||
# 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
|
||||
|
||||
kwargs = {
|
||||
"message": record.msg,
|
||||
"component": record.component,
|
||||
"level": record.levelno,
|
||||
}
|
||||
|
||||
if hasattr(record, "group"):
|
||||
kwargs["group"] = record.group
|
||||
|
||||
Log.objects.create(**kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue