diff options
Diffstat (limited to 'py/python/Ice.py')
-rw-r--r-- | py/python/Ice.py | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/py/python/Ice.py b/py/python/Ice.py index fb24d729a08..41d55c4a79f 100644 --- a/py/python/Ice.py +++ b/py/python/Ice.py @@ -12,7 +12,7 @@ Ice module """ -import sys, exceptions, string, imp, os, threading, warnings +import sys, exceptions, string, imp, os, threading, warnings, datetime try: import dl @@ -599,7 +599,7 @@ class CtrlCHandler(threading.Thread): signal.signal(signal.SIGHUP, signal.SIG_DFL) signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) - self._self = None + CtrlCHandler._self = None def setCallback(self, callback): self._condVar.acquire() @@ -624,6 +624,45 @@ class CtrlCHandler(threading.Thread): signalHandler = classmethod(signalHandler) # +# Application logger. +# +class ApplicationLoggerI(Logger): + def __init__(self, prefix): + if len(prefix) > 0: + self._prefix = prefix + ": " + else: + self._prefix = "" + self._outputMutex = threading.Lock() + + def _print(self, message): + s = "[ " + str(datetime.datetime.now()) + " " + self._prefix + self._outputMutex.acquire() + sys.stderr.write(message + "\n") + self._outputMutex.release() + + def trace(self, category, message): + s = "[ " + str(datetime.datetime.now()) + " " + self._prefix + if len(category) > 0: + s += category + ": " + s += message + " ]" + + s = s.replace("\n", "\n ") + + self._outputMutex.acquire() + sys.stderr.write(s + "\n") + self._outputMutex.release() + + def warning(self, message): + self._outputMutex.acquire() + sys.stderr.write(str(datetime.datetime.now()) + " " + self._prefix + "warning: " + message + "\n") + self._outputMutex.release() + + def error(self, message): + self._outputMutex.acquire() + sys.stderr.write(str(datetime.datetime.now()) + " " + self._prefix + "error: " + message + "\n") + self._outputMutex.release() + +# # Application class. # import signal, traceback @@ -640,6 +679,30 @@ class Application(object): return 1 # + # We parse the properties here to extract Ice.ProgramName. + # + if not initData: + initData = InitializationData() + if configFile: + try: + initData.properties = createProperties(None, initData.properties) + initData.properties.load(configFile) + except: + traceback.print_exc() + return 1 + print "args before createProps: " + str(args) + initData.properties = createProperties(args, initData.properties) + print "args after createProps: " + str(args) + print "props: " + str(initData.properties.getPropertiesForPrefix("")) + + # + # If the process logger is the default logger, we replace it with a + # a logger which is using the program name for the prefix. + # + if isinstance(getProcessLogger(), LoggerI): + setProcessLogger(ApplicationLoggerI(initData.properties.getProperty("Ice.ProgramName"))) + + # # Install our handler for the signals we are interested in. We assume main() # is called from the main thread. # @@ -650,12 +713,6 @@ class Application(object): Application._interrupted = False Application._appName = args[0] - - if not initData: - initData = InitializationData() - if configFile: - initData.properties = createProperties() - initData.properties.load(configFile) Application._application = self Application._communicator = initialize(args, initData) Application._destroyed = False |