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):
|
||||
_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
|
|
@ -5,17 +5,17 @@
|
|||
<field name="model">ir.logging</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Log" version="7.0">
|
||||
<sheet>
|
||||
<field name="name" />
|
||||
<field name="type" />
|
||||
<group>
|
||||
<field name="create_date" />
|
||||
<field name="dbname" />
|
||||
<field name="type" />
|
||||
<field name="name" />
|
||||
<field name="level" />
|
||||
<field name="message" />
|
||||
<field name="exception" />
|
||||
<field name="path" />
|
||||
<field name="func" />
|
||||
<field name="line" />
|
||||
</sheet>
|
||||
<field name="func" />
|
||||
<field name="message" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -23,13 +23,14 @@
|
|||
<field name="model">ir.logging</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Logs" version="7.0">
|
||||
<field name="level" />
|
||||
<field name="type" />
|
||||
<field name="create_date" />
|
||||
<field name="dbname" />
|
||||
<field name="type" />
|
||||
<field name="name" />
|
||||
<field name="level" />
|
||||
<field name="path" />
|
||||
<field name="func" />
|
||||
<field name="line" />
|
||||
<field name="func" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -37,11 +38,11 @@
|
|||
<field name="model">ir.logging</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Logs">
|
||||
<field name="name" />
|
||||
<field name="level" />
|
||||
<field name="dbname" />
|
||||
<field name="type" />
|
||||
|
||||
<field name="name" />
|
||||
<field name="level" />
|
||||
<field name="message" />
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Database" domain="[]" context="{'group_by': 'dbname'}" />
|
||||
<filter string="Level" domain="[]" context="{'group_by': 'level'}" />
|
||||
|
@ -50,7 +51,6 @@
|
|||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="ir_logging_all_act">
|
||||
<field name="name">Logging</field>
|
||||
<field name="res_model">ir.logging</field>
|
||||
|
@ -58,7 +58,6 @@
|
|||
<field name="view_mode">tree,form</field>
|
||||
<field name="search_view_id" ref="ir_logging_search_view" />
|
||||
</record>
|
||||
|
||||
<menuitem parent="base.menu_custom" id="ir_logging_all_menu" action="ir_logging_all_act" />
|
||||
|
||||
</data>
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue