[IMP] improve debug for --log-level=debug_sql
bzr revid: fp@tinyerp.com-20100918093052-nxapeqahzt4cpr2m
This commit is contained in:
parent
7abdaefd7c
commit
9c62cde38f
|
@ -132,6 +132,7 @@ class ExportService(object):
|
|||
LOG_NOTSET = 'notset'
|
||||
LOG_DEBUG_SQL = 'debug_sql'
|
||||
LOG_DEBUG_RPC = 'debug_rpc'
|
||||
LOG_DEBUG_RPC_ANSWER = 'debug_rpc_answer'
|
||||
LOG_DEBUG = 'debug'
|
||||
LOG_TEST = 'test'
|
||||
LOG_INFO = 'info'
|
||||
|
@ -139,9 +140,11 @@ LOG_WARNING = 'warn'
|
|||
LOG_ERROR = 'error'
|
||||
LOG_CRITICAL = 'critical'
|
||||
|
||||
logging.DEBUG_RPC_ANSWER = logging.DEBUG - 4
|
||||
logging.addLevelName(logging.DEBUG_RPC_ANSWER, 'DEBUG_RPC_ANSWER')
|
||||
logging.DEBUG_RPC = logging.DEBUG - 2
|
||||
logging.addLevelName(logging.DEBUG_RPC, 'DEBUG_RPC')
|
||||
logging.DEBUG_SQL = logging.DEBUG_RPC - 2
|
||||
logging.DEBUG_SQL = logging.DEBUG_RPC - 3
|
||||
logging.addLevelName(logging.DEBUG_SQL, 'DEBUG_SQL')
|
||||
|
||||
logging.TEST = logging.INFO - 5
|
||||
|
@ -157,6 +160,7 @@ COLOR_PATTERN = "%s%s%%s%s" % (COLOR_SEQ, COLOR_SEQ, RESET_SEQ)
|
|||
LEVEL_COLOR_MAPPING = {
|
||||
logging.DEBUG_SQL: (WHITE, MAGENTA),
|
||||
logging.DEBUG_RPC: (BLUE, WHITE),
|
||||
logging.DEBUG_RPC_ANSWER: (BLUE, WHITE),
|
||||
logging.DEBUG: (BLUE, DEFAULT),
|
||||
logging.INFO: (GREEN, DEFAULT),
|
||||
logging.TEST: (WHITE, BLUE),
|
||||
|
@ -420,11 +424,11 @@ class OpenERPDispatcherException(Exception):
|
|||
self.traceback = traceback
|
||||
|
||||
class OpenERPDispatcher:
|
||||
def log(self, title, msg):
|
||||
def log(self, title, msg, channel=logging.DEBUG_RPC, depth=2):
|
||||
logger = logging.getLogger(title)
|
||||
if logger.isEnabledFor(logging.DEBUG_RPC):
|
||||
for line in pformat(msg).split('\n'):
|
||||
logger.log(logging.DEBUG_RPC, line)
|
||||
if logger.isEnabledFor(channel):
|
||||
for line in pformat(msg, depth=depth).split('\n'):
|
||||
logger.log(channel, line)
|
||||
|
||||
def dispatch(self, service_name, method, params):
|
||||
try:
|
||||
|
@ -433,10 +437,8 @@ class OpenERPDispatcher:
|
|||
self.log('params', params)
|
||||
auth = getattr(self, 'auth_provider', None)
|
||||
result = ExportService.getService(service_name).dispatch(method, auth, params)
|
||||
self.log('result', result)
|
||||
# We shouldn't marshall None,
|
||||
if result == None:
|
||||
result = False
|
||||
logger = logging.getLogger('result')
|
||||
self.log('result', result, channel=logging.DEBUG_RPC_ANSWER, depth=(logger.isEnabledFor(logging.DEBUG_SQL) and 1 or None))
|
||||
return result
|
||||
except Exception, e:
|
||||
self.log('exception', tools.exception_to_unicode(e))
|
||||
|
|
|
@ -113,8 +113,6 @@ class Cursor(object):
|
|||
self.__logger.warn(query)
|
||||
self.__logger.warn("SQL queries cannot contain %d or %f anymore. "
|
||||
"Use only %s")
|
||||
if params:
|
||||
query = query.replace('%d', '%s').replace('%f', '%s')
|
||||
|
||||
if self.sql_log:
|
||||
now = mdt.now()
|
||||
|
@ -167,6 +165,7 @@ class Cursor(object):
|
|||
sqllogitems = sqllogs[type].items()
|
||||
sqllogitems.sort(key=lambda k: k[1][1])
|
||||
self.__logger.log(logging.DEBUG_SQL, "SQL LOG %s:", type)
|
||||
sqllogitems.sort(lambda x,y: cmp(x[1][0], y[1][0]))
|
||||
for r in sqllogitems:
|
||||
delay = timedelta(microseconds=r[1][1])
|
||||
self.__logger.log(logging.DEBUG_SQL, "table: %s: %s/%s",
|
||||
|
|
|
@ -98,7 +98,7 @@ class configmanager(object):
|
|||
self.has_ssl = check_ssl()
|
||||
|
||||
self._LOGLEVELS = dict([(getattr(netsvc, 'LOG_%s' % x), getattr(logging, x))
|
||||
for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'TEST', 'DEBUG', 'DEBUG_RPC', 'DEBUG_SQL', 'NOTSET')])
|
||||
for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'TEST', 'DEBUG', 'DEBUG_RPC', 'DEBUG_SQL', 'DEBUG_RPC_ANSWER','NOTSET')])
|
||||
|
||||
version = "%s %s" % (release.description, release.version)
|
||||
self.parser = parser = optparse.OptionParser(version=version)
|
||||
|
|
Loading…
Reference in New Issue