Commit b6cebd9b authored by HERBERT Ryan's avatar HERBERT Ryan
Browse files

UserLogHandler.py Added databse storage handler

Added a handler designed to store logs in the database
parent 8a646b07
import logging
class UserLogHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.table = 'user_log'
def emit(self, record):
if hasattr(record, 'user_id') and hasattr(record, 'record_id'):
db[self.table].insert(
user_id=record.user_id,
table_name=record.table_name,
created=datetime.datetime.now(),
msg=record.message,
record_id=record.record_id
)
db.commit()
......@@ -295,6 +295,7 @@ def _init_log():
logger.addHandler(create_handler(defs.LOG_DEBUG, logging.DEBUG))
logger.addHandler(create_handler(defs.LOG_INFO, logging.INFO))
logger.addHandler(UserLogHandler())
logger.debug("Creating logger")
return MsgUserAdapter(logger, {})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment