How to use the foolscap.logging.flogfile 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 / foolscap / logging / gatherer.py View on Github external
def save_incident(self, filename, incident):
        now = time.time()
        (header, events) = incident
        f = bz2.BZ2File(filename, "w")
        flogfile.serialize_raw_header(f, header)
        for e in events:
            flogfile.serialize_wrapper(f, e, from_=self.tubid_s, rx_time=now)
        f.close()
github warner / foolscap / foolscap / logging / gatherer.py View on Github external
def save_incident(self, filename, incident):
        now = time.time()
        (header, events) = incident
        f = bz2.BZ2File(filename, "w")
        flogfile.serialize_raw_header(f, header)
        for e in events:
            flogfile.serialize_wrapper(f, e, from_=self.tubid_s, rx_time=now)
        f.close()
github warner / foolscap / src / foolscap / logging / tail.py View on Github external
def remote_msg(self, d):
        try:
            flogfile.serialize_wrapper(self.f, d,
                                       from_=self.nodeid_s,
                                       rx_time=time.time())
        except Exception as ex:
            print("GATHERER: unable to serialize %s: %s" % (d, ex))
github warner / foolscap / src / foolscap / logging / log.py View on Github external
def __init__(self, filename, level=OPERATIONAL):
        if filename.endswith(".bz2"):
            # py3: bz2file ignores "b", only accepts bytes, not str
            import bz2
            f = bz2.BZ2File(filename, "w")
        else:
            f = open(filename, "wb")
        self._logFile = f # todo: line_buffering=True ?
        self._level = level
        self._logFile.write(flogfile.MAGIC)
        flogfile.serialize_header(self._logFile,
                                  "log-file-observer",
                                  versions=app_versions.versions,
                                  pid=os.getpid(),
                                  threshold=level)
github warner / foolscap / src / foolscap / logging / filter.py View on Github external
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
                    and e['d'].get('facility', "").startswith(strip_facility)):
                    continue
            copied += 1
            flogfile.serialize_raw_wrapper(newfile, e)
        newfile.close()
        if options.newfile == options.oldfile:
            if sys.platform == "win32":
                # Win32 can't do an atomic rename to an existing file.
                try:
                    os.unlink(options.newfile)
                except OSError:
                    pass
            move_into_place(newfilename, options.newfile)
        print >>stdout, "copied %d of %d events into new file" % (copied, total)
github warner / foolscap / foolscap / logging / gatherer.py View on Github external
def msg(self, nodeid_s, d):
        try:
            flogfile.serialize_wrapper(self._savefile, d,
                                       from_=nodeid_s,
                                       rx_time=time.time())
        except Exception, ex:
            print "GATHERER: unable to serialize %s: %s" % (d, ex)
github warner / foolscap / foolscap / logging / incident.py View on Github external
unique = os.urandom(4)
        unique_s = base32.encode(unique)
        self.name = "incident-%s-%s" % (self.format_time(now), unique_s)
        filename = self.name + ".flog"
        self.abs_filename = os.path.join(self.basedir, filename)
        self.abs_filename_bz2 = self.abs_filename + ".bz2"
        self.abs_filename_bz2_tmp = self.abs_filename + ".bz2.tmp"
        # open logfile. We use both an uncompressed one and a compressed one.
        try:
            self.f1 = open(self.abs_filename, "wb")
            self.f2 = bz2.BZ2File(self.abs_filename_bz2_tmp, "wb")
        except EnvironmentError as e:
            raise IncidentDeclarationError(e)

        # write header with triggering_event
        flogfile.serialize_header(self.f1, "incident",
                                  trigger=triggering_event,
                                  versions=app_versions.versions,
                                  pid=os.getpid())
        flogfile.serialize_header(self.f2, "incident",
                                  trigger=triggering_event,
                                  versions=app_versions.versions,
                                  pid=os.getpid())

        if self.TRAILING_DELAY is not None:
            # subscribe to events that occur after this one
            self.still_recording = True
            self.remaining_events = self.TRAILING_EVENT_LIMIT
            self.logger.addObserver(self.trailing_event)

        # use self.logger.buffers, copy events into logfile
        events = list(self.logger.get_buffered_events())