harvester-d4science/ckanext/harvest/log.py

16 lines
449 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
class DBLogHandler(Handler):
def __init__(self, level=NOTSET):
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()
2016-04-25 19:53:49 +02:00
except Exception as exc:
2016-04-05 20:21:04 +02:00
pass