Introduce 'debug2' loglevel, use it for SQL

Sometimes we want to debug SQL, not always though.

bzr revid: p_christ@hol.gr-20090814160111-fhw1j4jmx94t2hjv
This commit is contained in:
P. Christeas 2009-08-14 19:01:11 +03:00
parent 00d15e79fe
commit e571324ab3
2 changed files with 9 additions and 2 deletions

View File

@ -78,13 +78,15 @@ def service_exist(name):
LOG_NOTSET = 'notset'
LOG_DEBUG_RPC = 'debug_rpc'
LOG_DEBUG = 'debug'
LOG_DEBUG2 = 'debug2'
LOG_INFO = 'info'
LOG_WARNING = 'warn'
LOG_ERROR = 'error'
LOG_CRITICAL = 'critical'
# add new log level below DEBUG
logging.DEBUG_RPC = logging.DEBUG - 1
logging.DEBUG2 = logging.DEBUG - 1
logging.DEBUG_RPC = logging.DEBUG2 - 1
def init_logger():
import os
@ -144,6 +146,7 @@ def init_logger():
mapping = {
'DEBUG_RPC': ('blue', 'white'),
'DEBUG2': ('green', 'white'),
'DEBUG': ('blue', 'default'),
'INFO': ('green', 'default'),
'WARNING': ('yellow', 'default'),
@ -163,6 +166,10 @@ class Logger(object):
log = logging.getLogger(tools.ustr(name))
if level == LOG_DEBUG2 and not hasattr(log, level):
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG2, msg, *args, **kwargs)
setattr(log, LOG_DEBUG2, fct)
if level == LOG_DEBUG_RPC and not hasattr(log, level):
fct = lambda msg, *args, **kwargs: log.log(logging.DEBUG_RPC, msg, *args, **kwargs)
setattr(log, LOG_DEBUG_RPC, fct)

View File

@ -55,7 +55,7 @@ from mx import DateTime as mdt
re_from = re.compile('.* from "?([a-zA-Z_0-9]+)"? .*$');
re_into = re.compile('.* into "?([a-zA-Z_0-9]+)"? .*$');
def log(msg, lvl=netsvc.LOG_DEBUG):
def log(msg, lvl=netsvc.LOG_DEBUG2):
logger = netsvc.Logger()
logger.notifyChannel('sql', lvl, msg)