[FIX] logging: sys.stdout has not a fileno() method when running behind mod_wsgi.

bzr revid: vmt@openerp.com-20130206103459-2mmgagrh59c23804
This commit is contained in:
Vo Minh Thu 2013-02-06 11:34:59 +01:00
parent 3a2286bd78
commit 941f6ebc10
1 changed files with 7 additions and 1 deletions

View File

@ -186,7 +186,13 @@ def init_logger():
# Normal Handler on standard output
handler = logging.StreamHandler(sys.stdout)
if isinstance(handler, logging.StreamHandler) and os.isatty(handler.stream.fileno()):
# Check that handler.stream has a fileno() method: when running OpenERP
# behind Apache with mod_wsgi, handler.stream will have type mod_wsgi.Log,
# which has no fileno() method. (mod_wsgi.Log is what is being bound to
# sys.stderr when the logging.StreamHandler is being constructed above.)
if isinstance(handler, logging.StreamHandler) \
and hasattr(handler.stream, 'fileno') \
and os.isatty(handler.stream.fileno()):
formatter = ColoredFormatter(format)
else:
formatter = DBFormatter(format)