How to use the foolscap.logging.log 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 / tail.py View on Github external
def formatted_print(self, d):
        time_s = format_time(d['time'], self.options["timestamps"])

        msg = log.format_message(d)
        level = d.get('level', log.OPERATIONAL)

        tubid = "" # TODO
        print("%s L%d [%s]#%d %s" % (time_s, level, tubid,
                                     d["num"], msg), file=self.output)
        if 'failure' in d:
            print(" FAILURE:", file=self.output)
            lines = str(d['failure']).split("\n")
            for line in lines:
                print(" %s" % (line,), file=self.output)
github warner / foolscap / src / foolscap / call.py View on Github external
def complete(self, res):
        if self.broker:
            self.broker.removeRequest(self)
        if self.active:
            self.active = False
            self.deferred.callback(res)
        else:
            log.msg("PendingRequest.complete called on an inactive request")
github warner / foolscap / src / foolscap / call.py View on Github external
def logFailure(self, f):
        # called if tub.logLocalFailures is True
        my_short_tubid = "??"
        if self.broker.tub: # for tests
            my_short_tubid = self.broker.tub.getShortTubID()
        their_short_tubid = ""
        if self.broker.remote_tubref:
            their_short_tubid = self.broker.remote_tubref.getShortTubID()
        lp = log.msg("an inbound callRemote that we [%s] executed (on behalf "
                     "of someone else, TubID %s) failed"
                     % (my_short_tubid, their_short_tubid),
                     level=log.UNUSUAL)
        if self.interface:
            methname = self.interface.getName() + "." + self.methodname
        else:
            methname = self.methodname
        log.msg(" reqID=%d, rref=%s, methname=%s" %
                (self.reqID, self.obj, methname),
                level=log.NOISY, parent=lp)
        log.msg(" args=%s" % (self.allargs.args,), level=log.NOISY, parent=lp)
        log.msg(" kwargs=%s" % (self.allargs.kwargs,),
                level=log.NOISY, parent=lp)
        #if isinstance(f.type, str):
        #    stack = "getTraceback() not available for string exceptions\n"
        #else:
        #    stack = f.getTraceback()
        # TODO: trim stack to everything below Broker._doCall
        #stack = "LOCAL: " + stack.replace("\n", "\nLOCAL: ")
github warner / foolscap / src / foolscap / broker.py View on Github external
def connectionLost(self, why):
        tubid = "?"
        if self.remote_tubref:
            tubid = self.remote_tubref.getShortTubID()
        log.msg("connection to %s lost" % tubid, facility="foolscap.connection")
        banana.Banana.connectionLost(self, why)
        self.finish(why)
        self._notifyConnectionLostWatchers()
github warner / foolscap / src / foolscap / call.py View on Github external
my_short_tubid = self.broker.tub.getShortTubID()
        their_short_tubid = ""
        if self.broker.remote_tubref:
            their_short_tubid = self.broker.remote_tubref.getShortTubID()
        lp = log.msg("an inbound callRemote that we [%s] executed (on behalf "
                     "of someone else, TubID %s) failed"
                     % (my_short_tubid, their_short_tubid),
                     level=log.UNUSUAL)
        if self.interface:
            methname = self.interface.getName() + "." + self.methodname
        else:
            methname = self.methodname
        log.msg(" reqID=%d, rref=%s, methname=%s" %
                (self.reqID, self.obj, methname),
                level=log.NOISY, parent=lp)
        log.msg(" args=%s" % (self.allargs.args,), level=log.NOISY, parent=lp)
        log.msg(" kwargs=%s" % (self.allargs.kwargs,),
                level=log.NOISY, parent=lp)
        #if isinstance(f.type, str):
        #    stack = "getTraceback() not available for string exceptions\n"
        #else:
        #    stack = f.getTraceback()
        # TODO: trim stack to everything below Broker._doCall
        #stack = "LOCAL: " + stack.replace("\n", "\nLOCAL: ")
        log.msg(" the LOCAL failure was:", failure=f,
                level=log.NOISY, parent=lp)
        #log.msg(stack, level=log.NOISY, parent=lp)
github warner / foolscap / foolscap / negotiate.py View on Github external
def __init__(self, protoparent, logparent=None):
        self._protoparent = protoparent
        self._logparent = log.msg("Negotiation started", parent=logparent,
                                  facility="foolscap.negotiation")
        for i in range(self.minVersion, self.maxVersion+1):
            assert hasattr(self, "evaluateNegotiationVersion%d" % i), i
            assert hasattr(self, "acceptDecisionVersion%d" % i), i
        assert isinstance(self.initialVocabTableRange, tuple)
        self.negotiationOffer = {
            "banana-negotiation-range": "%d %d" % (self.minVersion,
                                                   self.maxVersion),
            "initial-vocab-table-range": "%d %d" % self.initialVocabTableRange,
            }
        # TODO: for testing purposes, it might be useful to be able to add
        # some keys to this offer
        if self.forceNegotiation is not None:
            # TODO: decide how forcing should work. Maybe forceNegotiation
            # should be a dict of keys or something. distinguish between
            # offer and decision.
github warner / foolscap / src / foolscap / logging / web.py View on Github external
self.anchor_index = "no-number"
        self.incarnation = base32.encode(e['d']['incarnation'][0].encode("utf-8"))
        if 'num' in e['d']:
            self.index = (e['from'], e['d']['num'])
            self.anchor_index = "%s_%s_%d" % (quote(e['from'].encode("utf-8")),
                                              self.incarnation.encode("utf-8"),
                                              e['d']['num'])
        self.parent_index = None
        if 'parent' in e['d']:
            self.parent_index = (e['from'], e['d']['parent'])
        self.is_trigger = False

    LEVELMAP = {
        log.NOISY: "NOISY",
        log.OPERATIONAL: "OPERATIONAL",
        log.UNUSUAL: "UNUSUAL",
        log.INFREQUENT: "INFREQUENT",
        log.CURIOUS: "CURIOUS",
        log.WEIRD: "WEIRD",
        log.SCARY: "SCARY",
        log.BAD: "BAD",
        }

    def level_class(self):
        level = self.e['d'].get('level', log.OPERATIONAL)
        return self.LEVELMAP.get(level, "UNKNOWN")

    def to_html(self, href_base="", timestamps="short-local"):
        # this must return bytes to satisfy twisted.web, but the logfile is
        # JSON so we get unicode here
        d = self.e['d']
        time_short, time_extended = web_format_time(d['time'], timestamps)
github warner / foolscap / src / foolscap / pb.py View on Github external
def setup(self, _test_options):
        self._test_options = _test_options
        self.logger = flog.theLogger
        self.listeners = []
        self.locationHints = []

        # duplicate-connection management
        self.make_incarnation()

        # the master_table records the master-seqnum we used for the last
        # established connection with the given tubid. It only contains
        # entries for which we were the master.
        self.master_table = {} # k:tubid, v:seqnum
        # the slave_table records the (master-IR,master-seqnum) pair for the
        # last established connection with the given tubid. It only contains
        # entries for which we were the slave.
        self.slave_table = {} # k:tubid, v:(master-IR,seqnum)

        # local Referenceables
github warner / foolscap / src / foolscap / connection.py View on Github external
def __init__(self, parent, tubref, connectionPlugins):
        self._logparent = log.msg(format="TubConnector created from "
                                  "%(fromtubid)s to %(totubid)s",
                                  fromtubid=parent.tubID,
                                  totubid=tubref.getTubID(),
                                  level=OPERATIONAL,
                                  facility="foolscap.connection",
                                  umid="pH4QDA")
        self.tub = parent
        self.target = tubref
        self.connectionPlugins = connectionPlugins
        self._connectionInfo = ConnectionInfo()
        self.remainingLocations = list(self.target.getLocations())
        # attemptedLocations keeps track of where we've already tried to
        # connect, so we don't try them twice, even if they appear in the
        # hints multiple times. this isn't too clever: slight variations of
        # the same hint will fool it, but it should be enough to avoid
        # infinite redirection loops.
github warner / foolscap / src / foolscap / call.py View on Github external
level=log.UNUSUAL)
                methname = ".".join([self.interfaceName or "?",
                                     self.methodName or "?"])
                log.msg(" reqID=%d, rref=%s, methname=%s"
                        % (self.reqID, self.rref, methname),
                        level=log.NOISY, parent=lp)
                #stack = why.getTraceback()
                # TODO: include the first few letters of the remote tubID in
                # this REMOTE tag
                #stack = "REMOTE: " + stack.replace("\n", "\nREMOTE: ")
                log.msg(" the REMOTE failure was:", failure=why,
                        level=log.NOISY, parent=lp)
                #log.msg(stack, level=log.NOISY, parent=lp)
            self.deferred.errback(why)
        else:
            log.msg("WEIRD: fail() on an inactive request", traceback=True)
            if self.failure:
                log.msg("multiple failures")
                log.msg("first one was:", self.failure)
                log.msg("this one was:", why)
                log.err("multiple failures indicate a problem")