# -*- coding: utf-8 -*-

from logging import Handler
from datetime import datetime 

class DBLogHandler(Handler, object):
    def __init__(self):
        super(DBLogHandler, self).__init__()
    
    def emit(self, record):
        from models import DBLogEntry as _LogEntry
        
        entry = _LogEntry()
        entry.level = record.levelname
        entry.message = self.format(record)
        if record.event:
            entry.event = record.event
        if record.user:
            entry.user = record.user
        entry.save()


@@ -400,23 +400,46 @@
     
-if record.event
+entry.module = record.name%0A        try
 :%0A  
@@ -487,22 +487,44 @@
     
-if record.user
+except:%0A            pass%0A        try
 :%0A  
@@ -558,16 +558,49 @@
 rd.user%0A
+        except:%0A            pass%0A
         

Handle optional field saving with exceptions, save module name.