[IMP] openerp.netsvc: use the same logging format for werkzeug and gunicorn
but not for the access logs (we keep the Combined format). With multiple processes, using a FileHandler can possibly produce garbled lines. Using syslog is a good alternative. bzr revid: vmt@openerp.com-20120126110135-9t04z5zrmag45g0b
This commit is contained in:
parent
a83bf232ee
commit
1f64224006
|
@ -138,6 +138,7 @@ LEVEL_COLOR_MAPPING = {
|
||||||
|
|
||||||
class DBFormatter(logging.Formatter):
|
class DBFormatter(logging.Formatter):
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
|
record.pid = os.getpid()
|
||||||
record.dbname = getattr(threading.currentThread(), 'dbname', '?')
|
record.dbname = getattr(threading.currentThread(), 'dbname', '?')
|
||||||
return logging.Formatter.format(self, record)
|
return logging.Formatter.format(self, record)
|
||||||
|
|
||||||
|
@ -153,6 +154,7 @@ def init_logger():
|
||||||
|
|
||||||
# create a format for log messages and dates
|
# create a format for log messages and dates
|
||||||
format = '[%(asctime)s][%(dbname)s] %(levelname)s:%(name)s:%(message)s'
|
format = '[%(asctime)s][%(dbname)s] %(levelname)s:%(name)s:%(message)s'
|
||||||
|
format = '%(asctime)s %(levelname)s %(pid)s %(dbname)s %(name)s: %(message)s'
|
||||||
|
|
||||||
if tools.config['syslog']:
|
if tools.config['syslog']:
|
||||||
# SysLog Handler
|
# SysLog Handler
|
||||||
|
@ -194,6 +196,31 @@ def init_logger():
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
logger.setLevel(int(tools.config['log_level'] or '0'))
|
logger.setLevel(int(tools.config['log_level'] or '0'))
|
||||||
|
|
||||||
|
# We could do this ...
|
||||||
|
#logger = logging.getLogger('werkzeug')
|
||||||
|
#logger.addHandler(handler)
|
||||||
|
#logger.setLevel(int(tools.config['log_level'] or '0'))
|
||||||
|
|
||||||
|
# ... or this but they have the standard Combined log format
|
||||||
|
# and it is better to keep it.
|
||||||
|
# TODO gunicorn access logs are configured from the gunicorn config file.
|
||||||
|
# Offer something similar for the stand-alone Werkzeug mode.
|
||||||
|
#logger = logging.getLogger('gunicorn.access')
|
||||||
|
#logger.handlers = []
|
||||||
|
#logger.addHandler(handler)
|
||||||
|
#logger.setLevel(int(tools.config['log_level'] or '0'))
|
||||||
|
|
||||||
|
# For the other logs, use the same format than openerp.
|
||||||
|
logger = logging.getLogger('gunicorn.error')
|
||||||
|
logger.handlers = []
|
||||||
|
logger.addHandler(handler)
|
||||||
|
logger.setLevel(int(tools.config['log_level'] or '0'))
|
||||||
|
|
||||||
|
logger = logging.getLogger('gunicorn.http.wsgi')
|
||||||
|
logger.handlers = []
|
||||||
|
logger.addHandler(handler)
|
||||||
|
logger.setLevel(int(tools.config['log_level'] or '0'))
|
||||||
|
|
||||||
# A alternative logging scheme for automated runs of the
|
# A alternative logging scheme for automated runs of the
|
||||||
# server intended to test it.
|
# server intended to test it.
|
||||||
def init_alternative_logger():
|
def init_alternative_logger():
|
||||||
|
|
Loading…
Reference in New Issue