[IMP] [CLEAN] [REVIEW] field._properties -> isinstance(field, fields.function).
[odoo/odoo.git] / openerp / netsvc.py
index 5adaba6..e9b1309 100644 (file)
@@ -3,7 +3,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2011 OpenERP SA (<http://www.openerp.com>)
+#    Copyright (C) 2004-2012 OpenERP SA (<http://www.openerp.com>)
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -54,7 +54,7 @@ def close_socket(sock):
         # of the other side (or something), see
         # http://bugs.python.org/issue4397
         # note: stdlib fixed test, not behavior
-        if e.errno != errno.ENOTCONN or platform.system() != 'Darwin':
+        if e.errno != errno.ENOTCONN or platform.system() not in ['Darwin', 'Windows']:
             raise
     sock.close()
 
@@ -86,12 +86,12 @@ class Service(object):
             cls._services.pop(name)
 
 def LocalService(name):
-  # Special case for addons support, will be removed in a few days when addons
-  # are updated to directly use openerp.osv.osv.service.
-  if name == 'object_proxy':
-      return openerp.osv.osv.service
+    # Special case for addons support, will be removed in a few days when addons
+    # are updated to directly use openerp.osv.osv.service.
+    if name == 'object_proxy':
+        return openerp.osv.osv.service
 
-  return Service._services[name]
+    return Service._services[name]
 
 class ExportService(object):
     """ Proxy for exported services.
@@ -189,26 +189,38 @@ def init_logger():
     handler.setFormatter(formatter)
 
     # Configure handlers
-    logconfig = tools.config['log_handler']
+    default_config = [
+        'openerp.netsvc.rpc.request:INFO',
+        'openerp.netsvc.rpc.response:INFO',
+        'openerp.addons.web.http:INFO',
+        'openerp.sql_db:INFO',
+        ':INFO',
+    ]
+
     if tools.config['log_level'] == 'info':
         pseudo_config = []
     elif tools.config['log_level'] == 'debug_rpc':
-        pseudo_config = ['openerp.netsvc.rpc.request:DEBUG']
+        pseudo_config = ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG']
     elif tools.config['log_level'] == 'debug_rpc_answer':
-        pseudo_config = ['openerp.netsvc.rpc.request:DEBUG', 'openerp.netsvc.rpc.response:DEBUG']
+        pseudo_config = ['openerp:DEBUG','openerp.netsvc.rpc.request:DEBUG', 'openerp.netsvc.rpc.response:DEBUG']
     elif tools.config['log_level'] == 'debug':
         pseudo_config = ['openerp:DEBUG']
-    elif tools.config['log_level'] == 'critical':
-        pseudo_config = ['openerp:CRITICAL']
     elif tools.config['log_level'] == 'test':
         pseudo_config = ['openerp:TEST']
-    elif tools.config['log_level'] == 'error':
-        pseudo_config = ['openerp:ERROR']
     elif tools.config['log_level'] == 'warn':
         pseudo_config = ['openerp:WARNING']
+    elif tools.config['log_level'] == 'error':
+        pseudo_config = ['openerp:ERROR']
+    elif tools.config['log_level'] == 'critical':
+        pseudo_config = ['openerp:CRITICAL']
     elif tools.config['log_level'] == 'debug_sql':
         pseudo_config = ['openerp.sql_db:DEBUG']
-    for logconfig_item in logconfig + pseudo_config:
+    else:
+        pseudo_config = []
+
+    logconfig = tools.config['log_handler']
+
+    for logconfig_item in default_config + pseudo_config + logconfig:
         loggername, level = logconfig_item.split(':')
         level = getattr(logging, level, logging.INFO)
         logger = logging.getLogger(loggername)
@@ -218,16 +230,16 @@ def init_logger():
         if loggername != '':
             logger.propagate = False
 
-    for logconfig_item in logconfig + pseudo_config:
+    for logconfig_item in default_config + pseudo_config + logconfig:
         _logger.debug('logger level set: "%s"', logconfig_item)
 
 # A alternative logging scheme for automated runs of the
 # server intended to test it.
 def init_alternative_logger():
     class H(logging.Handler):
-      def emit(self, record):
-        if record.levelno > 20:
-          print record.levelno, record.pathname, record.msg
+        def emit(self, record):
+            if record.levelno > 20:
+                print record.levelno, record.pathname, record.msg
     handler = H()
     # Add the handler to the 'openerp' logger.
     logger = logging.getLogger('openerp')
@@ -344,6 +356,8 @@ def dispatch_rpc(service_name, method, params):
             if rpc_request and rpc_response_flag:
                 log(rpc_request,logging.DEBUG,'%s.%s'%(service_name,method), replace_request_password(params))
 
+        threading.current_thread().uid = None
+        threading.current_thread().dbname = None
         result = ExportService.getService(service_name).dispatch(method, params)
 
         if rpc_request_flag or rpc_response_flag:
@@ -361,11 +375,11 @@ def dispatch_rpc(service_name, method, params):
     except openerp.exceptions.Warning:
         raise
     except openerp.exceptions.DeferredException, e:
-        _logger.error(tools.exception_to_unicode(e))
+        _logger.exception(tools.exception_to_unicode(e))
         post_mortem(e.traceback)
         raise
     except Exception, e:
-        _logger.error(tools.exception_to_unicode(e))
+        _logger.exception(tools.exception_to_unicode(e))
         post_mortem(sys.exc_info())
         raise