Commit 58bf5bdd authored by HERBERT Ryan's avatar HERBERT Ryan

UserLogHandler changes

Moved class UserLogHandler to db.py in order to resolve issues
encountered with first logging test in patient.py
parent da3ff9a6
......@@ -242,7 +242,7 @@ def index():
for row in result :
row['string'] = [row['last_name'], row['first_name'], row['confs'], row['groups'], str(row['birth']), str(row['info'])]
result = filter(lambda row : vidjil_utils.advanced_filter(row['string'],request.vars["filter"]), result )
log.debug("patient list (%.3fs) %s" % (time.time()-start, request.vars["filter"]))
log.debug("patient list (%.3fs) %s" % (time.time()-start, request.vars["filter"]), extra={'user_id':auth.user_id, 'table_name':'patient', 'record_id':0})
return dict(query = result,
isAdmin = isAdmin,
reverse = reverse)
......
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()
......@@ -276,6 +276,24 @@ class MsgUserAdapter(logging.LoggerAdapter):
def admin(self, msg):
self.log(logging.ADMIN, msg)
#
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'):
from datetime import datetime
now = datetime.now()
current.db[self.table].insert(
user_id=record.user_id,
table_name=record.table_name,
created=now,
msg=record.message,
record_id=record.record_id
)
db.commit()
def _init_log():
"""
......
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