I have the following handler:
import logging
from peewee import *
db = SqliteDatabase("my_app.db")
class Log(Model):
message = CharField()
class Meta:
database = db
Log.create_table(db)
class DatabaseHandler(logging.Handler):
def emit(self, record):
try:
event = Log(
message=record.message
)
event.save()
except Exception:
self.handleError(record)
And when I do:
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(DatabaseHandler)
logger.info("something")
I get the following error message:
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
File "/home/raf/miniconda3/lib/python3.7/logging/__init__.py", line 1383, in info
self._log(INFO, msg, args, **kwargs)
File "/home/raf/miniconda3/lib/python3.7/logging/__init__.py", line 1519, in _log
self.handle(record)
File "/home/raf/miniconda3/lib/python3.7/logging/__init__.py", line 1529, in handle
self.callHandlers(record)
File "/home/raf/miniconda3/lib/python3.7/logging/__init__.py", line 1590, in callHandlers
if record.levelno >= hdlr.level:
AttributeError: type object 'DatabaseHandler' has no attribute 'level'
I only could find this error in one other place (https://github.com/GNS3/gns3-gui/issues/2109) and it has no solution.
It's probably because I wrote the handler incorrectly, I'd appreciate it if anyone could help!