harvester-d4science/ckanext/harvest/log.py

18 lines
445 B
Python
Raw Normal View History

from logging import Handler, NOTSET
2016-04-05 20:21:04 +02:00
from ckanext.harvest.model import HarvestLog
2019-03-06 12:19:05 +01:00
class DBLogHandler(Handler):
def __init__(self, level=NOTSET):
2019-03-06 12:19:05 +01:00
super(DBLogHandler, self).__init__(level=level)
2016-04-05 20:21:04 +02:00
def emit(self, record):
try:
level = record.levelname
msg = self.format(record)
obj = HarvestLog(level=level, content=msg)
obj.save()
2019-03-06 12:19:05 +01:00
except Exception:
pass