def flushThreadLog(threadList):
    #global threadDict
    #global logThreadLock
    currentThread = threading.currentThread()
    for thread in threadList:
        if thread == currentThread:
            continue
        elif currentThread.getName() not in LOGGING_THREADS:
            for msg in threadDict[thread]['msgList']:
                logThreadLock.acquire()
                debug('flushThreadLog - lock acquired by thread %s' %
                      thread.threadId,
                      level=const.LEVEL4)
                try:
                    threadDict[currentThread]['msgList'].append(msg)
                except:
                    sys.__stdout__.write(sys.exc_info())
                    logThreadLock.release()
                    debug('flushThreadLog - lock released by thread %s' %
                          thread.threadId,
                          level=const.LEVEL4)
                logThreadLock.release()
                debug('flushThreadLog - lock released by thread %s' %
                      thread.threadId,
                      level=const.LEVEL4)
            threadDict.pop(thread, None)
        else:
            for msg in threadDict[thread]['msgList']:
                LOGGER.log_message(msg)
            threadDict.pop(thread, None)
Exemple #2
0
 def write(self, msg, level, html=False):
     with self.lock:
         thread = threading.currentThread().getName()
         if thread in self.LOGGING_THREADS:
             LOGGER.log_message(Message(msg, level, html))
         else:
             message = Message(msg, level, html)
             self._messages.setdefault(thread, []).append(message)
def debug(msg, html=True, timestamp=None, level=0):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            LOGGER.log_message(logMsg)
    else:
        if level <= debugLogLevel:
            logMsg = Message(msg,'DEBUG',html,timestamp=timestamp)
            if currentThread in threadDict:
                threadDict[currentThread]['msgList'].append(logMsg)
            else:
                threadDict[currentThread]['msgList'] = []
                threadDict[currentThread]['msgList'].append(logMsg)
def debug(msg, html=True, timestamp=None, level=0):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            LOGGER.log_message(logMsg)
    else:
        if level <= debugLogLevel:
            logMsg = Message(msg, 'DEBUG', html, timestamp=timestamp)
            if currentThread in threadDict:
                threadDict[currentThread]['msgList'].append(logMsg)
            else:
                threadDict[currentThread]['msgList'] = []
                threadDict[currentThread]['msgList'].append(logMsg)
def info(msg, html=False, also_console=True,timestamp=None):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(logMsg)
        if also_console:
            sys.__stdout__.write('\n %s' %(msg))
    else:
        if also_console:
             sys.__stdout__.write("\n%s" %(msg))
        logMsg = Message(msg,'INFO',html,timestamp=timestamp)
        if currentThread in threadDict:
            threadDict[currentThread]['msgList'].append(logMsg)
        else:
            threadDict[currentThread]['msgList'] = []
            threadDict[currentThread]['msgList'].append(logMsg)
def info(msg, html=False, also_console=True, timestamp=None):
    currentThread = threading.currentThread()
    if currentThread.getName() in LOGGING_THREADS:
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(logMsg)
        if also_console:
            sys.__stdout__.write('\n %s' % (msg))
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % (msg))
        logMsg = Message(msg, 'INFO', html, timestamp=timestamp)
        if currentThread in threadDict:
            threadDict[currentThread]['msgList'].append(logMsg)
        else:
            threadDict[currentThread]['msgList'] = []
            threadDict[currentThread]['msgList'].append(logMsg)
Exemple #7
0
def details(msg, html=True, also_console=True, timestamp=None):
    current_thread = threading.currentThread()
    if current_thread.getName() in LOGGING_THREADS:
        log_msg = Message(msg, 'INFO', html, timestamp=timestamp)
        LOGGER.log_message(log_msg)
        if also_console:
            sys.__stdout__.write('\n\x1b[5;36mINFO          : %s\x1b[0m' % msg)
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % msg)
        log_msg = Message(msg, 'INFO', html, timestamp=timestamp)
        if current_thread in threadDict:
            threadDict[current_thread]['msg_list'].append(log_msg)
        else:
            threadDict[current_thread]['msg_list'] = []
            threadDict[current_thread]['msg_list'].append(log_msg)
Exemple #8
0
def fail(msg, html=True, also_console=True, timestamp=None):
    font_tag = '<font color=\"red\"><b> FAIL: '
    font_end_tag = '</b></font>'
    failmsg = "%s %s %s" % (font_tag, msg, font_end_tag)
    current_thread = threading.currentThread()
    sys.__stdout__.write('\n\x1b[38;5;1mFAIL: %s\x1b[0m' % msg)
    if current_thread.getName() in LOGGING_THREADS:
        log_msg = Message(failmsg, 'FAIL', html, timestamp=timestamp)
        LOGGER.log_message(log_msg)
        if also_console:
            sys.__stdout__.write('\n %s' % msg)
    else:
        if also_console:
            sys.__stdout__.write("\n%s" % msg)
        log_msg = Message(msg, 'FAIL', html, timestamp=timestamp)
        if current_thread in threadDict:
            threadDict[current_thread]['msg_list'].append(log_msg)
        else:
            threadDict[current_thread]['msg_list'] = []
            threadDict[current_thread]['msg_list'].append(log_msg)
def flushThreadLog(threadList):
    #global threadDict
    #global logThreadLock
    currentThread = threading.currentThread()
    for thread in threadList:
        if thread == currentThread:
            continue
        elif currentThread.getName() not in LOGGING_THREADS:
            for msg in threadDict[thread]['msgList']:
                logThreadLock.acquire()
                debug('flushThreadLog - lock acquired by thread %s' %thread.threadId, level=const.LEVEL4)
                try:
                    threadDict[currentThread]['msgList'].append(msg)
                except:
                    sys.__stdout__.write(sys.exc_info())
                    logThreadLock.release()
                    debug('flushThreadLog - lock released by thread %s' %thread.threadId, level=const.LEVEL4)
                logThreadLock.release()
                debug('flushThreadLog - lock released by thread %s' %thread.threadId, level=const.LEVEL4)
            threadDict.pop(thread, None)
        else:
            for msg in threadDict[thread]['msgList']:
                LOGGER.log_message(msg)
            threadDict.pop(thread, None)
Exemple #10
0
 def emit(self, record):
     message = self.format(record)
     level = MAP.get(record.levelname, record.levelname)
     LOGGER.log_message(Message(message, level, False))
Exemple #11
0
 def _log_all_messages(self):
     for thread in list(self._messages):
         # Only way to get custom timestamps currently is with print
         print("*HTML* <b>Messages by '%s'</b>" % thread)
         for message in self._messages.pop(thread):
             LOGGER.log_message(message)
Exemple #12
0
 def _log_messages_by_thread(self, name, html=False):
     msg = 'Run Thread %s' % name
     LOGGER.log_message(Message(msg, 'INFO', html))
     for message in self._messages.pop(name, []):
         LOGGER.log_message(message)