From 2bc319d919ca7c2de535017d13c5635f761dbdf4 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 26 Dec 2008 16:05:51 +0100 Subject: [PATCH] [FIX] encoding problems with the logger lp bug: https://launchpad.net/bugs/311528 fixed bzr revid: christophe@taupe-20081226150551-bk3rfyzba2lq2emu --- bin/netsvc.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index 5a718f0c7a6..bc0d5362468 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -115,7 +115,6 @@ class Service(object): self._response = s(self._response_process_id) def abortResponse(self, error, description, origin, details): - import tools if not tools.config['debug_mode']: raise Exception("%s -- %s\n\n%s"%(origin, description, details)) else: @@ -152,12 +151,11 @@ LOG_CRITICAL = 'critical' logging.DEBUG_RPC = logging.DEBUG - 1 def init_logger(): - from tools import config import os logger = logging.getLogger() - if config['syslog']: + if tools.config['syslog']: # SysLog Handler if os.name == 'nt': sysloghandler = logging.handlers.NTEventLogHandler("%s %s" % @@ -171,9 +169,9 @@ def init_logger(): # create a format for log messages and dates formatter = logging.Formatter('[%(asctime)s] %(levelname)s:%(name)s:%(message)s', '%a %b %d %Y %H:%M:%S') - if config['logfile']: + if tools.config['logfile']: # LogFile Handler - logf = config['logfile'] + logf = tools.config['logfile'] try: dirname = os.path.dirname(logf) if dirname and not os.path.isdir(dirname): @@ -192,7 +190,7 @@ def init_logger(): # add the handler to the root logger logger.addHandler(handler) - logger.setLevel(config['log_level'] or '0') + logger.setLevel(tools.config['log_level'] or '0') if isinstance(handler, logging.StreamHandler) and os.name != 'nt': # change color of level names @@ -240,13 +238,14 @@ class Logger(object): level_method = getattr(log, level) - result = str(msg).strip().split('\n') + result = tools.ustr(msg).strip().split('\n') if len(result)>1: for idx, s in enumerate(result): level_method('[%02d]: %s' % (idx+1, s,), extra=extra) elif result: level_method(result[0], extra=extra) +import tools init_logger() class Agent(object): @@ -303,7 +302,6 @@ class GenericXMLRPCRequestHandler: self.log('exception', e) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) s = str(e) - import tools if tools.config['debug_mode']: import pdb tb = sys.exc_info()[2] @@ -314,7 +312,6 @@ class SSLSocket(object): def __init__(self, socket): if not hasattr(socket, 'sock_shutdown'): from OpenSSL import SSL - import tools ctx = SSL.Context(SSL.SSLv23_METHOD) ctx.use_privatekey_file(tools.config['secure_pkey_file']) ctx.use_certificate_file(tools.config['secure_cert_file']) @@ -441,7 +438,6 @@ class TinySocketClientThread(threading.Thread): except Exception, e: print repr(e) tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)) - import tools if tools.config['debug_mode']: import pdb tb = sys.exc_info()[2]