ir_logging make it work, and make it usable
bzr revid: al@openerp.com-20140316191622-l59vkjeu2e8nbh75
This commit is contained in:
parent
3168c3c1ca
commit
eaacd8a4d8
|
@ -24,6 +24,7 @@ from openerp.tools.translate import _
|
||||||
|
|
||||||
class ir_logging(osv.Model):
|
class ir_logging(osv.Model):
|
||||||
_name = 'ir.logging'
|
_name = 'ir.logging'
|
||||||
|
_order = 'id DESC'
|
||||||
|
|
||||||
EXCEPTIONS_TYPE = [
|
EXCEPTIONS_TYPE = [
|
||||||
('client', 'Client'),
|
('client', 'Client'),
|
||||||
|
@ -31,22 +32,14 @@ class ir_logging(osv.Model):
|
||||||
]
|
]
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
|
'create_date': fields.datetime('Create Date', readonly=True),
|
||||||
'name': fields.char('Name', required=True),
|
'name': fields.char('Name', required=True),
|
||||||
'type': fields.selection(EXCEPTIONS_TYPE, string='Type', required=True, select=True),
|
'type': fields.selection(EXCEPTIONS_TYPE, string='Type', required=True, select=True),
|
||||||
'dbname': fields.char('Database Name'),
|
'dbname': fields.char('Database Name'),
|
||||||
'level': fields.char('Level'),
|
'level': fields.char('Level'),
|
||||||
'message': fields.text('Message', required=True),
|
'message': fields.text('Message', required=True),
|
||||||
'exception': fields.text('Exception'),
|
|
||||||
'path': fields.char('Path', required=True),
|
'path': fields.char('Path', required=True),
|
||||||
'func': fields.char('Function', required=True),
|
'func': fields.char('Function', required=True),
|
||||||
'line': fields.char('Line', 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
|
|
|
@ -5,17 +5,17 @@
|
||||||
<field name="model">ir.logging</field>
|
<field name="model">ir.logging</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Log" version="7.0">
|
<form string="Log" version="7.0">
|
||||||
<sheet>
|
<group>
|
||||||
<field name="name" />
|
<field name="create_date" />
|
||||||
<field name="type" />
|
|
||||||
<field name="dbname" />
|
<field name="dbname" />
|
||||||
|
<field name="type" />
|
||||||
|
<field name="name" />
|
||||||
<field name="level" />
|
<field name="level" />
|
||||||
<field name="message" />
|
|
||||||
<field name="exception" />
|
|
||||||
<field name="path" />
|
<field name="path" />
|
||||||
<field name="func" />
|
|
||||||
<field name="line" />
|
<field name="line" />
|
||||||
</sheet>
|
<field name="func" />
|
||||||
|
<field name="message" />
|
||||||
|
</group>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -23,13 +23,14 @@
|
||||||
<field name="model">ir.logging</field>
|
<field name="model">ir.logging</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Logs" version="7.0">
|
<tree string="Logs" version="7.0">
|
||||||
<field name="level" />
|
<field name="create_date" />
|
||||||
<field name="type" />
|
|
||||||
<field name="dbname" />
|
<field name="dbname" />
|
||||||
|
<field name="type" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="level" />
|
||||||
<field name="path" />
|
<field name="path" />
|
||||||
<field name="func" />
|
|
||||||
<field name="line" />
|
<field name="line" />
|
||||||
|
<field name="func" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
@ -37,11 +38,11 @@
|
||||||
<field name="model">ir.logging</field>
|
<field name="model">ir.logging</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search string="Logs">
|
<search string="Logs">
|
||||||
<field name="name" />
|
|
||||||
<field name="level" />
|
|
||||||
<field name="dbname" />
|
<field name="dbname" />
|
||||||
<field name="type" />
|
<field name="type" />
|
||||||
|
<field name="name" />
|
||||||
|
<field name="level" />
|
||||||
|
<field name="message" />
|
||||||
<group expand="0" string="Group By...">
|
<group expand="0" string="Group By...">
|
||||||
<filter string="Database" domain="[]" context="{'group_by': 'dbname'}" />
|
<filter string="Database" domain="[]" context="{'group_by': 'dbname'}" />
|
||||||
<filter string="Level" domain="[]" context="{'group_by': 'level'}" />
|
<filter string="Level" domain="[]" context="{'group_by': 'level'}" />
|
||||||
|
@ -50,7 +51,6 @@
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.actions.act_window" id="ir_logging_all_act">
|
<record model="ir.actions.act_window" id="ir_logging_all_act">
|
||||||
<field name="name">Logging</field>
|
<field name="name">Logging</field>
|
||||||
<field name="res_model">ir.logging</field>
|
<field name="res_model">ir.logging</field>
|
||||||
|
@ -58,8 +58,7 @@
|
||||||
<field name="view_mode">tree,form</field>
|
<field name="view_mode">tree,form</field>
|
||||||
<field name="search_view_id" ref="ir_logging_search_view" />
|
<field name="search_view_id" ref="ir_logging_search_view" />
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem parent="base.menu_custom" id="ir_logging_all_menu" action="ir_logging_all_act" />
|
<menuitem parent="base.menu_custom" id="ir_logging_all_menu" action="ir_logging_all_act" />
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
|
|
@ -76,28 +76,26 @@ class PostgreSQLHandler(logging.Handler):
|
||||||
the current database, can be set using --log-db=DBNAME
|
the current database, can be set using --log-db=DBNAME
|
||||||
"""
|
"""
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
print "Emit PG", record
|
|
||||||
ct = threading.current_thread()
|
ct = threading.current_thread()
|
||||||
ct_db = getattr(ct, 'dbname')
|
ct_db = getattr(ct, 'dbname', None)
|
||||||
ct_uid = getattr(ct, 'uid')
|
ct_uid = getattr(ct, 'uid', None)
|
||||||
dbname = tools.config['log_db'] or ct_db
|
dbname = tools.config['log_db'] or ct_db
|
||||||
if dbname:
|
if dbname:
|
||||||
cr = None
|
cr = None
|
||||||
try:
|
try:
|
||||||
cr = sql_db.db_connect(dbname).cursor()
|
cr = sql_db.db_connect(dbname).cursor()
|
||||||
exception = False
|
msg = record.msg
|
||||||
if record.exc_info:
|
traceback = getattr(record, 'exc_text', '')
|
||||||
exception = record.exc_text
|
if traceback:
|
||||||
|
msg = "%s\n%s" % (msg, traceback)
|
||||||
level = logging.getLevelName(record.levelno)
|
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("""
|
cr.execute("""
|
||||||
INSERT INTO ir_logging(create_date, write_date, create_uid, write_uid, type, dbname, name, level, message, exception, path, func, line)
|
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, %s)
|
VALUES (NOW() at time zone 'UTC', NOW() at time zone 'UTC', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||||
""", val )
|
""", val )
|
||||||
cr.commit()
|
cr.commit()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "Exception",e
|
|
||||||
print repr(e)
|
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
if cr:
|
if cr:
|
||||||
|
@ -187,6 +185,9 @@ def init_logger():
|
||||||
|
|
||||||
logconfig = tools.config['log_handler']
|
logconfig = tools.config['log_handler']
|
||||||
|
|
||||||
|
postgresqlHandler = PostgreSQLHandler()
|
||||||
|
postgresqlHandler.setLevel(logging.WARNING)
|
||||||
|
|
||||||
logging_configurations = DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig
|
logging_configurations = DEFAULT_LOG_CONFIGURATION + pseudo_config + logconfig
|
||||||
for logconfig_item in logging_configurations:
|
for logconfig_item in logging_configurations:
|
||||||
loggername, level = logconfig_item.split(':')
|
loggername, level = logconfig_item.split(':')
|
||||||
|
@ -195,18 +196,15 @@ def init_logger():
|
||||||
logger.handlers = []
|
logger.handlers = []
|
||||||
logger.setLevel(level)
|
logger.setLevel(level)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
logger.addHandler(postgresqlHandler)
|
||||||
if loggername != '':
|
if loggername != '':
|
||||||
logger.propagate = False
|
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:
|
for logconfig_item in logging_configurations:
|
||||||
_logger.debug('logger level set: "%s"', logconfig_item)
|
_logger.debug('logger level set: "%s"', logconfig_item)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_LOG_CONFIGURATION = [
|
DEFAULT_LOG_CONFIGURATION = [
|
||||||
'openerp.workflow.workitem:WARNING',
|
'openerp.workflow.workitem:WARNING',
|
||||||
'openerp.netsvc.rpc.request:INFO',
|
'openerp.netsvc.rpc.request:INFO',
|
||||||
|
|
Loading…
Reference in New Issue