From c90aedd04fb629a24f897ffb43fc5eec9a5435dc Mon Sep 17 00:00:00 2001 From: Samus CTO Date: Thu, 4 Dec 2014 13:07:31 +0100 Subject: [PATCH] [IMP] logging: Use the default python logging handler bound to stderr Avoid messing up actual output with logs. Useful when using odoo shell in a pipeline. Example: echo "for i in env['res.partner'].search([]): print i.email" | ./odoo.py shell -d master | xargs -n1 echo cmd --- openerp/addons/test_workflow/models.py | 6 +++++- openerp/netsvc.py | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/openerp/addons/test_workflow/models.py b/openerp/addons/test_workflow/models.py index 383d8c31bce..ed05c57520b 100644 --- a/openerp/addons/test_workflow/models.py +++ b/openerp/addons/test_workflow/models.py @@ -1,12 +1,16 @@ # -*- coding: utf-8 -*- +import logging + import openerp.osv.orm +_logger = logging.getLogger(__name__) + class m(openerp.osv.orm.Model): """ A model for which we will define a workflow (see data.xml). """ _name = 'test.workflow.model' def print_(self, cr, uid, ids, s, context=None): - print ' Running activity `%s` for record %s' % (s, ids) + _logger.info('Running activity `%s` for record %s', s, ids) return True def print_a(self, cr, uid, ids, context=None): diff --git a/openerp/netsvc.py b/openerp/netsvc.py index 3036510f668..160d349addf 100644 --- a/openerp/netsvc.py +++ b/openerp/netsvc.py @@ -137,6 +137,8 @@ def init_logger(): # create a format for log messages and dates format = '%(asctime)s %(pid)s %(levelname)s %(dbname)s %(name)s: %(message)s' + # Normal Handler on stderr + handler = logging.StreamHandler() if tools.config['syslog']: # SysLog Handler @@ -163,10 +165,6 @@ def init_logger(): handler = logging.FileHandler(logf) except Exception: sys.stderr.write("ERROR: couldn't create the logfile directory. Logging to the standard output.\n") - handler = logging.StreamHandler(sys.stdout) - else: - # Normal Handler on standard output - handler = logging.StreamHandler(sys.stdout) # Check that handler.stream has a fileno() method: when running OpenERP # behind Apache with mod_wsgi, handler.stream will have type mod_wsgi.Log,