2015-12-13 15:11:22 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
import time
|
2016-04-05 12:30:50 +00:00
|
|
|
from datetime import datetime
|
2017-03-26 00:10:09 +00:00
|
|
|
from certidude.relational import RelationalMixin
|
2015-12-13 15:11:22 +00:00
|
|
|
|
2016-03-21 21:42:39 +00:00
|
|
|
class LogHandler(logging.Handler, RelationalMixin):
|
|
|
|
SQL_CREATE_TABLES = "log_tables.sql"
|
2015-12-13 15:11:22 +00:00
|
|
|
|
2016-03-21 21:42:39 +00:00
|
|
|
def __init__(self, uri):
|
2015-12-13 15:11:22 +00:00
|
|
|
logging.Handler.__init__(self)
|
2016-03-21 21:42:39 +00:00
|
|
|
RelationalMixin.__init__(self, uri)
|
|
|
|
|
2015-12-13 15:11:22 +00:00
|
|
|
def emit(self, record):
|
2016-03-21 21:42:39 +00:00
|
|
|
self.sql_execute("log_insert_entry.sql",
|
2016-04-05 12:30:50 +00:00
|
|
|
datetime.utcfromtimestamp(record.created),
|
2015-12-13 15:11:22 +00:00
|
|
|
record.name,
|
|
|
|
record.levelno,
|
|
|
|
record.levelname.lower(),
|
|
|
|
record.msg % record.args, record.module,
|
|
|
|
record.funcName,
|
|
|
|
record.lineno,
|
|
|
|
logging._defaultFormatter.formatException(record.exc_info) if record.exc_info else "",
|
|
|
|
record.process,
|
|
|
|
record.thread,
|
2016-03-21 21:42:39 +00:00
|
|
|
record.threadName)
|