How to use the foolscap.logging.flogfile.get_events function in foolscap

To help you get started, we’ve selected a few foolscap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github warner / foolscap / src / foolscap / logging / web.py View on Github external
def process_logfiles(self, logfiles):
        summaries = {}
        # build up a tree of events based upon parent/child relationships
        number_map = {}
        roots = []
        trigger_numbers = []
        first_event_from = None

        for lf in logfiles:
            (first_event_number, first_event_time) = (None, None)
            (last_event_number, last_event_time) = (None, None)
            num_events = 0
            levels = {}
            pid = None

            for e in flogfile.get_events(lf):
                if "header" in e:
                    h = e["header"]
                    if h["type"] == "incident":
                        t = h["trigger"]
                        trigger_numbers.append(t["num"])
                    pid = h.get("pid")
                    versions = h.get("versions", {})
                if "d" not in e:
                    continue # skip headers
                if not first_event_from:
                    first_event_from = e['from']
                le = LogEvent(e)
                if le.index:
                    number_map[le.index] = le
                if le.parent_index in number_map:
                    le.parent = number_map[le.parent_index]
github warner / foolscap / foolscap / logging / incident.py View on Github external
def load_incident(self, abs_fn):
        assert abs_fn.endswith(".bz2")
        events = flogfile.get_events(abs_fn, ignore_value_error=True)
        header = next(events)["header"]
        wrapped_events = [event["d"] for event in events]
        return (header, wrapped_events)
github warner / foolscap / foolscap / logging / publish.py View on Github external
def remote_get_incident(self, name):
        if not name.startswith("incident"):
            raise KeyError("bad incident name %s" % name)
        incident_dir = filepath.FilePath(self._logger.logdir)
        abs_fn = incident_dir.child(name).path + ".flog"
        try:
            fn = abs_fn + ".bz2"
            if not os.path.exists(fn):
                fn = abs_fn
            events = flogfile.get_events(fn)
            # note the generator isn't actually cycled yet, not until next()
            header = next(events)["header"]
        except EnvironmentError:
            raise KeyError("no incident named %s" % name)
        wrapped_events = [event["d"] for event in events]
        return (header, wrapped_events)
github warner / foolscap / src / foolscap / logging / filter.py View on Github external
print >>stdout, " --after: removing events before %s" % time.ctime(after)
        before = options['before']
        if before is not None:
            print >>stdout, " --before: removing events after %s" % time.ctime(before)
        above = options['above']
        if above:
            print >>stdout, " --above: removing events below level %d" % above
        from_tubid = options['from']
        if from_tubid:
            print >>stdout, " --from: retaining events only from tubid prefix %s" % from_tubid
        strip_facility = options['strip-facility']
        if strip_facility is not None:
            print >>stdout, "--strip-facility: removing events for %s and children" % strip_facility
        total = 0
        copied = 0
        for e in flogfile.get_events(options.oldfile):
            if options['verbose']:
                if "d" in e:
                    print >>stdout, e['d']['num']
                else:
                    print >>stdout, "HEADER"
            total += 1
            if "d" in e:
                if before is not None and e['d']['time'] >= before:
                    continue
                if after is not None and e['d']['time'] <= after:
                    continue
                if above is not None and e['d']['level'] < above:
                    continue
                if from_tubid is not None and not e['from'].startswith(from_tubid):
                    continue
                if (strip_facility is not None
github warner / foolscap / foolscap / logging / dumper.py View on Github external
def run(self, options):
        try:
            for e in flogfile.get_events(options.dumpfile):
                if "header" in e:
                    self.print_header(e, options)
                if "d" in e:
                    self.print_event(e, options)
        except EnvironmentError, e:
            # "flogtool dump FLOGFILE |less" is very common, and if you quit
            # it early with "q", the stdout pipe is broken and python dies
            # with a messy stacktrace. Catch and ignore that.
            if e.errno == errno.EPIPE:
                return 1
            raise
        except flogfile.ThisIsActuallyAFurlFileError:
            print >>options.stderr, textwrap.dedent("""\
                Error: %s appears to be a FURL file.
                Perhaps you meant to run 'flogtool tail' instead of 'flogtool
                dump'?"""
github warner / foolscap / foolscap / logging / publish.py View on Github external
def get_incident_trigger(self, abs_fn):
        events = flogfile.get_events(abs_fn)
        try:
            header = next(iter(events))
        except (EOFError, ValueError):
            return None
        assert header["header"]["type"] == "incident"
        trigger = header["header"]["trigger"]
        return trigger