[IMP] openerp.netsvc: use the same logging format for werkzeug and gunicorn
authorVo Minh Thu <vmt@openerp.com>
Thu, 26 Jan 2012 11:01:35 +0000 (12:01 +0100)
committerVo Minh Thu <vmt@openerp.com>
Thu, 26 Jan 2012 11:01:35 +0000 (12:01 +0100)
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

openerp/netsvc.py

index 51c65d5..989c1aa 100644 (file)
@@ -138,6 +138,7 @@ LEVEL_COLOR_MAPPING = {
 
 class DBFormatter(logging.Formatter):
     def format(self, record):
+        record.pid = os.getpid()
         record.dbname = getattr(threading.currentThread(), 'dbname', '?')
         return logging.Formatter.format(self, record)
 
@@ -153,6 +154,7 @@ def init_logger():
 
     # create a format for log messages and dates
     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']:
         # SysLog Handler
@@ -194,6 +196,31 @@ def init_logger():
     logger.addHandler(handler)
     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
 # server intended to test it.
 def init_alternative_logger():