2016-05-11 13:29:53 +02:00
|
|
|
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
|
|
|
|
2016-05-11 13:29:53 +02: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
|