Here is my complete model code for a sqlite logging handler. This works the 
first time the program is run, and after that I get an error:

<class 'sqlite3.ProgrammingError'> Cannot operate on a closed database.


*model mylogging.py:*

import logging
import logging.handlers


class AppHandler(logging.Handler): # Inherit from logging.Handler
    def __init__(self):
 logging.Handler.__init__(self)
 
 self._db = db


    def emit(self, record):
 
 args = {}
 args['loggername'] = record.name
 args['srclineno'] = record.lineno
 args['func'] = record.funcName
 args['level'] = record.levelname
 args['msg'] = record.msg
 try:
 args['type'] = record.args[0]
 except:
 args['type'] = None
 
 self._db.log.insert(**args)




log_db = DAL('sqlite://log.sqlite')
log_db.define_table('log',
 
 Field('loggername', 'string'), #unique=True
 Field('srclineno', 'string'), 
 Field('func', 'string'), 
 Field('level', 'string'), 
 Field('msg', 'string'), 
 Field('type', 'string'),
 )


import logging
logger = logging.getLogger("web2py.app.myapp")
logger.setLevel(logging.DEBUG)


logger.addHandler(AppHandler(log_db))
logger.debug('test log')



I don't understand how I'm causing this, as all as im doing is creating a 
second db instance and inserting using web2py DAL methods?

Reply via email to