
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()



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)
        entry.module = record.name
        try:
            entry.event = record.event
        except:
            pass
        try:
            entry.user = record.user
        except:
            pass
        entry.save()


Handle optional field saving with exceptions, save module name.
dblog: Handle optional field saving with exceptions, save module name.

  
  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.module = record.name
+         try:
              entry.event = record.event
-         if record.user:
+         except:
+             pass
+         try:
              entry.user = record.user
+         except:
+             pass
          entry.save()
  
  
Handle optional field saving with exceptions, save module name.
## Code Before:

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()


## Instruction:
Handle optional field saving with exceptions, save module name.
## Code After:

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)
        entry.module = record.name
        try:
            entry.event = record.event
        except:
            pass
        try:
            entry.user = record.user
        except:
            pass
        entry.save()

