diff --git a/openerp/addons/base/ir/ir_logging.py b/openerp/addons/base/ir/ir_logging.py index 66708aa729a..a2b4e606290 100644 --- a/openerp/addons/base/ir/ir_logging.py +++ b/openerp/addons/base/ir/ir_logging.py @@ -24,6 +24,7 @@ from openerp.tools.translate import _ class ir_logging(osv.Model): _name = 'ir.logging' + _order = 'id DESC' EXCEPTIONS_TYPE = [ ('client', 'Client'), @@ -31,22 +32,14 @@ class ir_logging(osv.Model): ] _columns = { + 'create_date': fields.datetime('Create Date', readonly=True), 'name': fields.char('Name', required=True), 'type': fields.selection(EXCEPTIONS_TYPE, string='Type', required=True, select=True), 'dbname': fields.char('Database Name'), 'level': fields.char('Level'), 'message': fields.text('Message', required=True), - 'exception': fields.text('Exception'), 'path': fields.char('Path', required=True), 'func': fields.char('Function', required=True), 'line': fields.char('Line', required=True), } - def call_function(self, cr, uid, ids, context=None): - logger = logging.getLogger() - logger.error("I think there is an error") - try: - raise Exception("I want to kill your process...") - except Exception, ex: - logger.exception("Please log me into the database") - return True \ No newline at end of file diff --git a/openerp/addons/base/ir/ir_logging_view.xml b/openerp/addons/base/ir/ir_logging_view.xml index d23e45f1d14..1fa5170387a 100644 --- a/openerp/addons/base/ir/ir_logging_view.xml +++ b/openerp/addons/base/ir/ir_logging_view.xml @@ -5,17 +5,17 @@ ir.logging
- - - + + + + - - - - + + + @@ -23,13 +23,14 @@ ir.logging - - + + + - + @@ -37,11 +38,11 @@ ir.logging - - - + + + @@ -50,7 +51,6 @@ - Logging ir.logging @@ -58,8 +58,7 @@ tree,form - - \ No newline at end of file + diff --git a/openerp/netsvc.py b/openerp/netsvc.py index a2c8f687f0f..af45301dbb4 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -76,28 +76,26 @@ class PostgreSQLHandler(logging.Handler): the current database, can be set using --log-db=DBNAME """ def emit(self, record): - print "Emit PG", record ct = threading.current_thread() - ct_db = getattr(ct, 'dbname') - ct_uid = getattr(ct, 'uid') + ct_db = getattr(ct, 'dbname', None) + ct_uid = getattr(ct, 'uid', None) dbname = tools.config['log_db'] or ct_db if dbname: cr = None try: cr = sql_db.db_connect(dbname).cursor() - exception = False - if record.exc_info: - exception = record.exc_text + msg = record.msg + traceback = getattr(record, 'exc_text', '') + if traceback: + msg = "%s\n%s" % (msg, traceback) level = logging.getLevelName(record.levelno) - val = (uid, uid, 'server', dbname, record.name, level, record.msg, exception, record.filename, record.funcName, record.lineno) + val = (ct_uid, ct_uid, 'server', dbname, record.name, level, msg, record.pathname, record.lineno, record.funcName) cr.execute(""" - INSERT INTO ir_logging(create_date, write_date, create_uid, write_uid, type, dbname, name, level, message, exception, path, func, line) - VALUES (NOW() at time zone 'UTC', NOW() at time zone 'UTC', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + INSERT INTO ir_logging(create_date, write_date, create_uid, write_uid, type, dbname, name, level, message, path, line, func) + VALUES (NOW() at time zone 'UTC', NOW() at time zone 'UTC', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """, val ) cr.commit() except Exception, e: - print "Exception",e - print repr(e) pass finally: if cr: @@ -187,6 +185,9 @@ def init_logger(): logconfig = tools.config['log_handler'] + postgresqlHandler = PostgreSQLHandler() + postgresqlHandler.setLevel(logging.WARNING) + logging_configurations = DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig for logconfig_item in logging_configurations: loggername, level = logconfig_item.split(':') @@ -195,18 +196,15 @@ def init_logger(): logger.handlers = [] logger.setLevel(level) logger.addHandler(handler) + logger.addHandler(postgresqlHandler) if loggername != '': logger.propagate = False - # we manage the connection in the postgresqlhandler - postgresqlHandler = PostgreSQLHandler() - postgresqlHandler.setLevel(logging.WARNING) - logger = logging.getLogger() - logger.addHandler(postgresqlHandler) - for logconfig_item in logging_configurations: _logger.debug('logger level set: "%s"', logconfig_item) + + DEFAULT_LOG_CONFIGURATION = [ 'openerp.workflow.workitem:WARNING', 'openerp.netsvc.rpc.request:INFO',