Ejemplo n.º 1
0
    def emit(self, eventDict):
        if eventDict["isError"]:
            level = logging.ERROR
        elif "level" in eventDict:
            level = eventDict["level"]
        else:
            level = logging.INFO
        if level < self.logLevel:
            return

        message = log.textFromEventDict(eventDict)
        if not message:
            return

        logElements = {
            "timestamp": self.formatTime(eventDict["time"]),
            "level": logging.getLevelName(level),
            "system": eventDict["system"],
            "text": message.replace("\n", "\n\t")
        }
        messageString = "{} {}".format(logElements["timestamp"],
                                       log._safeFormat("%(level)7s:[%(system)s]: %(text)s\n", logElements))
        print messageString.replace("\n", "")
        util.untilConcludes(self.write, messageString)
        util.untilConcludes(self.flush)
Ejemplo n.º 2
0
    def emit(self, eventDict):
        if not eventDict.has_key('level'):
            if eventDict.has_key('isError') and eventDict['isError']:
                eventDict['level'] = ERROR

            else:
                eventDict['level'] = TRACE

        if eventDict['level'] < self.level:
            return

        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        text = text.rstrip()
        text = text.expandtabs()
        text += '\n'
        text = text.encode('utf-8')

        util.untilConcludes(self.write, text)
        util.untilConcludes(self.flush)

        if eventDict['level'] >= CRITICAL:
            self.reactor.stop()
Ejemplo n.º 3
0
 def write(self, output):
   """Write a gec error report, possibly overwriting a previous one."""
   self.errorId = (self.errorId + 1) % GentleGecLogObserver.MAX_ERRORS
   filename = os.path.join(self._GecHandler__path, '%d-%d.gec.json' % (self.baseName, self.errorId))
   with open(filename, 'w') as f:
     util.untilConcludes(f.write, output)
     util.untilConcludes(f.flush)
Ejemplo n.º 4
0
    def emit(self, eventDict):
        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        if GLLogObserver.suppressed == GLLogObserver.limit_suppressed:
            # This code path flush the status of the broken log, in the case a flood is happen
            # for few moment or in the case something goes wrong when logging below.
            log.info("!! has been suppressed %d log lines due to error flood (last error %s)" %
                     (GLLogObserver.limit_suppressed, GLLogObserver.last_exception_msg) )

            GLLogObserver.suppressed = 0
            GLLogObserver.limit_suppressed += 5
            GLLogObserver.last_exception_msg = ""

        try:
            # in addition to escape sequence removal on logfiles we also quote html chars
            util.untilConcludes(self.write, timeStr + " " + log_encode_html(msgStr))
            util.untilConcludes(self.flush) # Hoorj!
        except Exception as excep:
            GLLogObserver.suppressed += 1
            GLLogObserver.last_exception_msg = str(excep)
Ejemplo n.º 5
0
class KeyValueFileObserver(SimpleFileObserver):
    ''' Returns a string of formatted key=value pairs.

    The string will include level, msg, and exc_*. Also includes any arbitrary
    data that was included in the eventDict except for certain common and
    uninteresting fields. All values in the key-value string are json-encoded.
    Complex objects like lists and dicts are ignored.

    For readability purposes the order of the fields is:

        * level
        * msg
        * exc_type, if present
        * exc_value, if present
        * arbitrary additional data sorted by key


    '''
    def emit(self, event):
        is_error = event.get('isError', False)
        try:
            text = self.format_kv(event)
        except Exception, e:
            text = 'Parse error: %s. Original message: %s' % \
                    (repr(e), formatEvent(event))
            is_error = True

        f = self.err if is_error else self.out

        util.untilConcludes(f.write, text + '\n')
        util.untilConcludes(f.flush)
Ejemplo n.º 6
0
    def emit(self, eventDict):
        """
        Extends method of the base class by providing support for log level.
        """
        if eventDict['isError']:
            level = logging.ERROR
        elif 'level' in eventDict:
            level = eventDict['level']
        else:
            level = logging.INFO
        if level < self.log_level:
            return

        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        time_str = self.formatTime(eventDict['time'])
        fmt_dict = {
            'level': logging.getLevelName(level),
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        msg_str = log._safeFormat(
            "%(level)8s:[%(system)s]: %(text)s\n", fmt_dict)

        util.untilConcludes(self.write, "{0} {1}".format(time_str, msg_str))
        util.untilConcludes(self.flush)
Ejemplo n.º 7
0
    def emit(self, eventDict):
        if not eventDict.has_key('level'):
            if eventDict.has_key('isError') and eventDict['isError']:
                eventDict['level'] = ERROR

            else:
                eventDict['level'] = TRACE

        if eventDict['level'] < self.level:
            return

        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        text = text.rstrip()
        text = text.expandtabs()
        text += '\n'
        text = text.encode('utf-8')

        util.untilConcludes(self.write, text)
        util.untilConcludes(self.flush)
        
        if eventDict['level'] >= CRITICAL:
            self.reactor.stop()
Ejemplo n.º 8
0
    def emit(self, eventDict):
        text = txlog.textFromEventDict(eventDict)
        if text is None:
            return

        util.untilConcludes(self.write, "%s\n" % text)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 9
0
    def emit(self, eventDict):
        edm = eventDict['message']
        if not edm:
            if eventDict['isError'] and eventDict.has_key('failure'):
                text = eventDict['failure'].getTraceback()
            elif eventDict.has_key('format'):
                try:
                    text = eventDict['format'] % eventDict
                except KeyboardInterrupt:
                    raise
                except:
                    try:
                        text = ('Invalid format string in log message: %s'
                                % eventDict)
                    except:
                        text = 'UNFORMATTABLE OBJECT WRITTEN TO LOG, MESSAGE LOST'
            else:
                # we don't know how to log this
                return
        else:
            text = ' '.join(map(str, edm))

        timeStr = time.strftime(self.timeFormat, time.localtime(eventDict['time']))
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = " [%(system)s] %(text)s\n" % fmtDict

        util.untilConcludes(self.write, timeStr + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 10
0
 def _emit(self, params):
     level = params.get('level', LOG_DEBUG)
     if level > self.verbosity:
         return
     msg = self._formatMessage(params) + '\r\n'
     util.untilConcludes(self.write, msg)
     util.untilConcludes(self.flush)
Ejemplo n.º 11
0
    def emit(self, eventDict):
        """Changing the default log format.

        Base method that writes cis log. Here we can access the log
        message and manipulate it as we need. For example, define
        the log format and filter out password from the message.
        This can be configured per service in cisconf with LOG_FORMATTERS
        tuple of pairs (pattern, replacement).

        TODO: This is a hack, twisted should have a better way of modifying
        its log format"""
        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        if isinstance(self.log_formatters, (list, tuple)):
            for pattern, replacement in self.log_formatters:
                text = re.sub(pattern, replacement, text)

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        msgStr = log._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write,
                            '%s %s %s' % (timeStr, self.log_prefix, msgStr))
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 12
0
    def emit(self, eventDict):
        """
        Handles formatting system log messages along with incrementing the objs
        error counters. The eventDict is generated by the arguments passed to each
        log level call. See the unittests for an example.
        """
        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        if GLLogObserver.suppressed == GLLogObserver.limit_suppressed:
            GLLogObserver.suppressed = 0
            GLLogObserver.limit_suppressed += 5
            GLLogObserver.last_exception_msg = ""

        try:
            # in addition to escape sequence removal on logfiles we also quote html chars
            util.untilConcludes(self.write, timeStr + " " + log_encode_html(msgStr))
            util.untilConcludes(self.flush) # Hoorj!
        except Exception as excep:
            GLLogObserver.suppressed += 1
            GLLogObserver.last_exception_msg = str(excep)
Ejemplo n.º 13
0
    def emit(self, eventDict):
        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        if GLLogObserver.suppressed == GLLogObserver.limit_suppressed:
            GLLogObserver.suppressed = 0
            GLLogObserver.limit_suppressed += 5
            GLLogObserver.last_exception_msg = ""

        try:
            # in addition to escape sequence removal on logfiles we also quote html chars
            util.untilConcludes(self.write, timeStr + " " + log_encode_html(msgStr))
            util.untilConcludes(self.flush) # Hoorj!
        except Exception as excep:
            GLLogObserver.suppressed += 1
            GLLogObserver.last_exception_msg = str(excep)
Ejemplo n.º 14
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n",
            "\n\t")}
        level = "INFO"
        # in the future twisted version, a new logging system might have better
        # support for logging levels. 
        logLevelMapping = {50: "CRITICAL", 40: "ERROR", 30: "WARNING", 20:
                "INFO", 10: "DEBUG", 0: "NOTSET"}
        if not "log_level" in eventDict:
            if "logLevel" in eventDict:
                try:
                    level = logLevelMapping[eventDict["logLevel"]]
                except KeyError:
                    level = None
            elif eventDict["isError"]:
                level = "CRITICAL" 
            else:
                level = "INFO"

        msgStr = _safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " <" + level + "> " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 15
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self._colorize(self.formatTime(eventDict["time"]), ColoredFileLogObserver.GREY_NORMAL)
        fmtDict = {"system": eventDict["system"], "text": text.replace("\n", "\n\t")}
        systemStr = ""
        systemStr = self._colorize(_safeFormat("[%(system)s]", fmtDict), ColoredFileLogObserver.GREY_NORMAL)
        textStr = _safeFormat("%(text)s", fmtDict)

        if textStr.startswith("SSH"):
            t = textStr.find("STDERR:")
            if t != -1:
                textStr = self._colorize(textStr[t + 8 :], ColoredFileLogObserver.RED_BOLD)
            else:
                textStr = self._colorize(textStr[textStr.find("STDOUT:") + 8 :], ColoredFileLogObserver.GREEN_BOLD)
            # only text for incoming data
            msgStr = textStr + "\n"
        else:
            # add system to the local logs
            # TODO: Make system more useful, not just "SSHChannel...".
            msgStr = systemStr + " " + textStr + "\n"

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 16
0
Archivo: log.py Proyecto: jcollie/txHA
def err(_stuff = None, _why = None, **kw):
    if logger is None:
        util.untilConcludes(stderr_write, repr((_stuff, _why, kw)))
        util.untilConcludes(stderr_flush)

    else:
        logger.err(_stuff, _why, **kw)
Ejemplo n.º 17
0
    def emit(self, eventDict):
        """Changing the default log format.

        Base method that writes cis log. Here we can access the log
        message and manipulate it as we need. For example, define
        the log format and filter out password from the message.
        This can be configured per service in cisconf with LOG_FORMATTERS
        tuple of pairs (pattern, replacement).

        TODO: This is a hack, twisted should have a better way of modifying
        its log format"""
        text = log.textFromEventDict(eventDict)
        if text is None:
            return

        if isinstance(self.log_formatters, (list,tuple)):
            for pattern, replacement in self.log_formatters:
                text = re.sub(pattern, replacement, text)

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = log._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, '%s %s %s' % (timeStr, self.log_prefix, msgStr))
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 18
0
Archivo: log.py Proyecto: jcollie/txHA
def msg(*args, **kw):
    if logger is None:
        util.untilConcludes(stderr_write, repr((args, kw)))
        util.untilConcludes(stderr_flush)

    else:
        logger.msg(*args, **kw)
Ejemplo n.º 19
0
 def wakeUp(self):
     """Send a byte to my connection."""
     try:
         util.untilConcludes(self.w.send, b"x")
     except OSError as e:
         if e.args[0] != errno.WSAEWOULDBLOCK:
             raise
Ejemplo n.º 20
0
    def emit(self, eventDict):

        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        if GLLogObserver.suppressed == GLLogObserver.limit_suppressed:
            # This code path flush the status of the broken log, in the case a flood is happen
            # for few moment or in the case something goes wrong when logging below.
            log.info("!! has been suppressed %d log lines due to error flood (last error %s)" %
                     (GLLogObserver.limit_suppressed, GLLogObserver.last_exception_msg) )

            GLLogObserver.suppressed = 0
            GLLogObserver.limit_suppressed += 5
            GLLogObserver.last_exception_msg = ""

        try:
            # in addition to escape sequence removal on logfiles we also quote html chars
            util.untilConcludes(self.write, timeStr + " " + log_encode_html(msgStr))
            util.untilConcludes(self.flush) # Hoorj!
        except Exception as excep:
            GLLogObserver.suppressed += 1
            GLLogObserver.last_exception_msg = str(excep)
Ejemplo n.º 21
0
    def emit(self, eventDict):
        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        if GLLogObserver.suppressed == GLLogObserver.limit_suppressed:
            GLLogObserver.suppressed = 0
            GLLogObserver.limit_suppressed += 5
            GLLogObserver.last_exception_msg = ""

        try:
            # in addition to escape sequence removal on logfiles we also quote html chars
            util.untilConcludes(self.write, timeStr + " " + log_encode_html(msgStr))
            util.untilConcludes(self.flush) # Hoorj!
        except Exception as excep:
            GLLogObserver.suppressed += 1
            GLLogObserver.last_exception_msg = str(excep)
Ejemplo n.º 22
0
    def emit(self, eventDict):
        """
        Extended base class' 'emit' method by log level support.
        """
        if eventDict['isError']:
            level = logging.ERROR
        elif 'level' in eventDict:
            level = eventDict['level']
        else:
            level = logging.INFO
        if level < self.log_level:
            return

        text = tx_log.textFromEventDict(eventDict)
        if text is None:
            return

        time_str = self.formatTime(eventDict['time'])
        fmt_dict = {
            'level': logging.getLevelName(level),
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        msg_str = tx_log._safeFormat("%(level)s:[%(system)s]:%(text)s\n",
                                     fmt_dict)

        tx_util.untilConcludes(self.write, time_str + " " + msg_str)
        tx_util.untilConcludes(self.flush)
    def emit(self, eventDict):
        text = txlog.textFromEventDict(eventDict)
        if text is None:
            return

        util.untilConcludes(self.write, "%s\n" % text)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 24
0
    def emit(self, eventDict):
        """
        Handles formatting system log messages along with incrementing the objs
        error counters. The eventDict is generated by the arguments passed to each
        log level call. See the unittests for an example.
        """
        if 'failure' in eventDict:
            vf = eventDict['failure']
            e_t, e_v, e_tb = vf.type, vf.value, vf.getTracebackObject()
            sys.excepthook(e_t, e_v, e_tb)

        text = twlog.textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        msgStr = twlog._safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write,
                            timeStr + " " + log_encode_html(msgStr))
        util.untilConcludes(self.flush)
Ejemplo n.º 25
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self._colorize(self.formatTime(eventDict['time']),
                                 ColoredFileLogObserver.GREY_NORMAL)
        fmtDict = {
            'system': eventDict['system'],
            'text': text.replace("\n", "\n\t")
        }
        systemStr = ""
        systemStr = self._colorize(_safeFormat("[%(system)s]", fmtDict),
                                   ColoredFileLogObserver.GREY_NORMAL)
        textStr = _safeFormat("%(text)s", fmtDict)

        if textStr.startswith("SSH"):
            t = textStr.find("STDERR:")
            if t != -1:
                textStr = self._colorize(textStr[t + 8:],
                                         ColoredFileLogObserver.RED_BOLD)
            else:
                textStr = self._colorize(textStr[textStr.find("STDOUT:") + 8:],
                                         ColoredFileLogObserver.GREEN_BOLD)
            # only text for incoming data
            msgStr = textStr + "\n"
        else:
            # add system to the local logs
            # TODO: Make system more useful, not just "SSHChannel...".
            msgStr = systemStr + " " + textStr + "\n"

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 26
0
def myFloEmit(self, eventDict):
    text = log.textFromEventDict(eventDict)
    if text is None:
        return
    self.timeFormat = "%Y%m%d-%H:%M:%S.%f %z"
    timeStr = self.formatTime(eventDict["time"])
    util.untilConcludes(self.write, timeStr + " " + text + "\n")
    util.untilConcludes(self.flush)
Ejemplo n.º 27
0
Archivo: log.py Proyecto: jcollie/txHA
    def send(self, event, text):
        global stderr_write
        global stderr_flush

        text += '\n'
        text = text.encode('utf-8')
        util.untilConcludes(stderr_write, text)
        util.untilConcludes(stderr_flush)
Ejemplo n.º 28
0
 def _write(self, format_string, *args):
     s = str(format_string)
     assert isinstance(s, type(''))
     if args:
         self._stream.write(s % args)
     else:
         self._stream.write(s)
     untilConcludes(self._stream.flush)
Ejemplo n.º 29
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if not text: return

        timeStr = self.formatTime(eventDict['time'])
        util.untilConcludes(self.write,
                            "%s %s\n" % (timeStr, text.replace("\n", "\n\t")))
        util.untilConcludes(self.flush)
Ejemplo n.º 30
0
 def write(self, output):
   """Write a gec error report, possibly overwriting a previous one
   """
   self.errorId = (self.errorId + 1) % GentleGecLogObserver.MAX_ERRORS
   filename = os.path.join(self._GecHandler__path, '%d-%d.gec.json' % (self.baseName, self.errorId))
   with open(filename, 'w') as f:
     util.untilConcludes(f.write, output)
     util.untilConcludes(f.flush)
Ejemplo n.º 31
0
def myFloEmit(self, eventDict):
    text = log.textFromEventDict(eventDict)
    if text is None:
        return None
    self.timeFormat = "%Y%m%d-%H:%M:%S.%f %z"
    timeStr = self.formatTime(eventDict["time"])
    util.untilConcludes(self.write, timeStr + " " + text + "\n")
    util.untilConcludes(self.flush)
Ejemplo n.º 32
0
 def wakeUp(self):
     """Send a byte to my connection.
     """
     try:
         util.untilConcludes(self.w.send, 'x')
     except socket.error, (err, msg):
         if err != errno.WSAEWOULDBLOCK:
             raise
Ejemplo n.º 33
0
 def write(self, format, *args):
     s = str(format)
     assert isinstance(s, type(''))
     if args:
         self.stream.write(s % args)
     else:
         self.stream.write(s)
     untilConcludes(self.stream.flush)
Ejemplo n.º 34
0
 def wakeUp(self):
     """Send a byte to my connection.
     """
     try:
         util.untilConcludes(self.w.send, 'x')
     except socket.error, (err, msg):
         if err != errno.WSAEWOULDBLOCK:
             raise
Ejemplo n.º 35
0
 def wakeUp(self):
     """Send a byte to my connection.
     """
     try:
         util.untilConcludes(self.w.send, b'x')
     except socket.error as e:
         if e.args[0] != errno.WSAEWOULDBLOCK:
             raise
Ejemplo n.º 36
0
 def emit(self, eventDict):
     """ah, logs should be pretty much as the app intended"""
     text = textFromEventDict(eventDict)
     if text is None:
         return
     text.replace("\n", "\n\t")
     untilConcludes(self.write, text)
     untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 37
0
Archivo: log.py Proyecto: jcollie/otx
    def emit(self, event):
        global stdout_write
        global stdout_flush
        global stderr_write
        global stderr_flush

        message = JournalMessage()
        
        if 'MESSAGE_ID' in event and event['MESSAGE_ID'] is not None:
            message.add('MESSAGE_ID', event['MESSAGE_ID'])

        if 'CODE_FILE' in event and event['CODE_FILE'] is not None:
            message.add('CODE_FILE', event['CODE_FILE'])

        if 'CODE_LINE' in event and event['CODE_LINE'] is not None:
            message.add('CODE_LINE', event['CODE_LINE'])

        if 'CODE_FUNC' in event and event['CODE_FUNC'] is not None:
            message.add('CODE_FUNC', event['CODE_FUNC'])

        if 'SYSLOG_IDENTIFIER' not in event and self.appname is not None:
            message.add('SYSLOG_IDENTIFIER', self.appname)

        if event.has_key('PRIORITY'):
            if event['PRIORITY'] is None:
                event['PRIORITY'] = DEBUG

            elif event['PRIORITY'] not in range(8):
                event['PRIORITY'] = DEBUG

        elif event.get('isError'):
            event['PRIORITY'] = ERROR

        else:
            event['PRIORITY'] = DEBUG

        message.add('PRIORITY', event['PRIORITY'])

        text = twisted.python.log.textFromEventDict(event)
        if text is None:
            return

        text = text.rstrip()
        text = text.expandtabs()

        message.add('MESSAGE', text)

        if self.journal.running:
            self.journal.transport.write(message.data)

        if not self.journal.running or 'SHLVL' in os.environ:
            text += '\n'
            text = text.encode('utf-8')
            util.untilConcludes(stderr_write, text)
            util.untilConcludes(stderr_flush)

        if event['PRIORITY'] <= CRITICAL:
            self.reactor.stop()
Ejemplo n.º 38
0
 def _write(self, data):
     if not self._stream:
         raise errors.ReportNotCreated
     if self._stream.closed:
         raise errors.ReportAlreadyClosed
     s = str(data)
     assert isinstance(s, type(''))
     self._stream.write(s)
     untilConcludes(self._stream.flush)
Ejemplo n.º 39
0
 def _write(self, data):
     if not self._stream:
         raise errors.ReportNotCreated
     if self._stream.closed:
         raise errors.ReportAlreadyClosed
     s = str(data)
     assert isinstance(s, type(''))
     self._stream.write(s)
     untilConcludes(self._stream.flush)
Ejemplo n.º 40
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, 'x')
         except OSError, e:
             if e.errno != errno.EAGAIN:
                 raise
Ejemplo n.º 41
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, 'x')
         except OSError, e:
             if e.errno != errno.EAGAIN:
                 raise
Ejemplo n.º 42
0
    def emit(self, eventDict):
        text = log.textFromEventDict(eventDict)
        if text is None:
            text = '<no text>'

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'time': timeStr, 'text': text}
        output = log._safeFormat('%(time)s %(text)s\n', fmtDict)
        util.untilConcludes(self.write, output)
        util.untilConcludes(self.flush)
 def write(self, output):
   """Write a GEC error report, making sure we do not overwrite an existing one
   """
   while True:
     filename = os.path.join(self.__path, str(uuid.uuid4()) + '.gec.json')
     if not os.path.exists(filename):
       with open(filename, 'w') as f:
         util.untilConcludes(f.write, output)
         util.untilConcludes(f.flush)
       break
Ejemplo n.º 44
0
    def emit(self, eventDict):
        text = tw_log.textFromEventDict(eventDict)
        if text is None:
            return

        fmtDict = {'system': eventDict['system'],
                   'text': text.replace("\n", "\n\t")}
        msgStr = tw_log._safeFormat("[%(system)s] %(text)s\n", fmtDict)
        util.untilConcludes(self.write, msgStr)
        util.untilConcludes(self.flush)
Ejemplo n.º 45
0
    def emit(self, eventDict):
        text = tw_log.textFromEventDict(eventDict)
        if text is None:
            return

        fmtDict = {'system': eventDict['system'],
                   'text': text.replace("\n", "\n\t")}
        msgStr = tw_log._safeFormat("[%(system)s] %(text)s\n", fmtDict)
        util.untilConcludes(self.write, msgStr)
        util.untilConcludes(self.flush)
Ejemplo n.º 46
0
 def write(self, output):
   """Write a GEC error report, making sure we do not overwrite an existing one
   """
   while True:
     filename = os.path.join(self.__path, str(uuid.uuid4()) + '.gec.json')
     if not os.path.exists(filename):
       with open(filename, 'w') as f:
         util.untilConcludes(f.write, output)
         util.untilConcludes(f.flush)
       break
Ejemplo n.º 47
0
	def quietEmit(self, eventDict):
		text = log.textFromEventDict(eventDict)
		if text is None:
			return
		formatDict = {
			"text": text.replace("\n", "\n\t")
		}
		msg = log._safeFormat("%(text)s\n", formatDict)
		util.untilConcludes(self.write, msg)
		util.untilConcludes(self.flush)
Ejemplo n.º 48
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     # We don't use fdesc.writeToFD since we need to distinguish
     # between EINTR (try again) and EAGAIN (do nothing).
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, 'x')
         except OSError, e:
             if e.errno != errno.EAGAIN:
                 raise
Ejemplo n.º 49
0
 def custom_emit(self, event_dict):
     """Custom emit for FileLogObserver"""
     text = log.textFromEventDict(event_dict)
     if text is None:
         return
     self.timeFormat = '[%Y-%m-%d %H:%M:%S %f]'
     time_str = self.formatTime(event_dict['time'])
     fmt_dict = {'text': text.replace("\n", "\n\t")}
     msg_str = log._safeFormat("%(text)s\n", fmt_dict)
     util.untilConcludes(self.write, time_str + " " + msg_str)
     util.untilConcludes(self.flush)
Ejemplo n.º 50
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = _safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 51
0
    def emit(self, eventDict):
        text = textFromEventDict(eventDict)
        if text is None:
            return

        timeStr = self.formatTime(eventDict['time'])
        fmtDict = {'system': eventDict['system'], 'text': text.replace("\n", "\n\t")}
        msgStr = _safeFormat("[%(system)s] %(text)s\n", fmtDict)

        util.untilConcludes(self.write, timeStr + " " + msgStr)
        util.untilConcludes(self.flush)  # Hoorj!
Ejemplo n.º 52
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it.
     """
     # We don't use fdesc.writeToFD since we need to distinguish
     # between EINTR (try again) and EAGAIN (do nothing).
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, 'x')
         except OSError, e:
             if e.errno != errno.EAGAIN:
                 raise
Ejemplo n.º 53
0
 def _write(self, format_string, *args):
     if not self._stream:
         raise errors.ReportNotCreated
     if self._stream.closed:
         raise errors.ReportAlreadyClosed
     s = str(format_string)
     assert isinstance(s, type(''))
     if args:
         self._stream.write(s % args)
     else:
         self._stream.write(s)
     untilConcludes(self._stream.flush)
Ejemplo n.º 54
0
 def wakeUp(self):
     """Write one byte to the pipe, and flush it."""
     # We don't use fdesc.writeToFD since we need to distinguish
     # between EINTR (try again) and EAGAIN (do nothing).
     if self.o is not None:
         try:
             util.untilConcludes(os.write, self.o, b"x")
         except OSError as e:
             # XXX There is no unit test for raising the exception
             # for other errnos. See #4285.
             if e.errno != errno.EAGAIN:
                 raise
Ejemplo n.º 55
0
    def _write(self, format, *args):
        """
        Safely write to the reporter's stream.

        @param format: A format string to write.
        @param args: The arguments for the format string.
        """
        s = str(format)
        assert isinstance(s, str)
        if args:
            self._stream.write(s % args)
        else:
            self._stream.write(s)
        untilConcludes(self._stream.flush)
Ejemplo n.º 56
0
 def postApplication(self):
     """
     To be called after the application is created: start the application
     and run the reactor. After the reactor stops, clean up PID files and
     such.
     """
     try:
         self.startApplication(self.application)
     except Exception as ex:
         statusPipe = self.config.get("statusPipe", None)
         if statusPipe is not None:
             # Limit the total length to the passed string to 100
             strippedError = str(ex)[:98]
             untilConcludes(os.write, statusPipe,
                            "1 %s" % (strippedError, ))
             untilConcludes(os.close, statusPipe)
         self.removePID(self.config['pidfile'])
         raise
     else:
         statusPipe = self.config.get("statusPipe", None)
         if statusPipe is not None:
             untilConcludes(os.write, statusPipe, "0")
             untilConcludes(os.close, statusPipe)
     self.startReactor(None, self.oldstdout, self.oldstderr)
     self.removePID(self.config['pidfile'])
Ejemplo n.º 57
0
    def postApplication(self):
        """
        Run the application.
        """
        try:
            self.startApplication(self.application)
        except Exception as ex:
            statusPipe = self.config.get("statusPipe", None)
            if statusPipe is not None:
                # Limit the total length to the passed string to 100
                strippedError = str(ex)[:98]
                untilConcludes(os.write, statusPipe,
                               "1 %s" % (strippedError, ))
                untilConcludes(os.close, statusPipe)
            self.removePID(self.config['pidfile'])
            raise
        else:
            statusPipe = self.config.get("statusPipe", None)
            if statusPipe is not None:
                untilConcludes(os.write, statusPipe, "0")
                untilConcludes(os.close, statusPipe)

        self._reactor.callLater(0, self.start_globaleaks)

        self.startReactor(None, self.oldstdout, self.oldstderr)

        self.removePID(self.config['pidfile'])
Ejemplo n.º 58
0
    def postApplication(self):
        """
        Run the application.
        """

        try:
            self.startApplication(self.application)
        except Exception as ex:
            statusPipe = self.config.get("statusPipe", None)
            if statusPipe is not None:
                # Limit the total length to the passed string to 100
                strippedError = str(ex)[:98]
                untilConcludes(os.write, statusPipe,
                               "1 %s" % (strippedError, ))
                untilConcludes(os.close, statusPipe)
            self.removePID(self.config['pidfile'])
            raise
        else:
            statusPipe = self.config.get("statusPipe", None)
            if statusPipe is not None:
                untilConcludes(os.write, statusPipe, "0")
                untilConcludes(os.close, statusPipe)

        if globaleaks_start():
            self.startReactor(None, self.oldstdout, self.oldstderr)
        else:
            log.err("Cannot start GlobaLeaks; please manual check the error.")
            quit(-1)

        self.removePID(self.config['pidfile'])
Ejemplo n.º 59
0
    def set(self, property, uid=None):
        """
        Store the given property as an extended attribute on the wrapped path.

        @param uid: The per-user identifier for per user properties.

        @param property: A L{WebDAVElement} to store.
        """
        key = self._encode(property.qname(), uid)
        value = compress(property.toxml(pretty=False))
        untilConcludes(setitem, self.attrs, key, value)

        # Update the resource because we've modified it
        self.resource.fp.restat()