[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
This commit is contained in:
Samus CTO
2015-01-18 19:05:01 +01:00
committed by Antony Lesuisse
parent 9850080eb0
commit c90aedd04f
2 changed files with 7 additions and 5 deletions
+5 -1
View File
@@ -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):
+2 -4
View File
@@ -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,