# Path: src/foolscap/logging/interfaces.py
# class RILogObserver(RemoteInterface):
#     __remote_name__ = "RILogObserver.foolscap.lothar.com"
#     def msg(logmsg=Event):
#         return None
#     def done():
#         return None
# 
#     def new_incident(name=Any(), trigger=Event):
#         # should this give (tubid, incarnation, trigger) like list_incidents?
#         return None
#     def done_with_incident_catchup():
#         return None


import six, os, sys, time
from zope.interface import implementer
from twisted.internet import reactor
from twisted.python import usage
from foolscap import base32
from foolscap.api import Tub, Referenceable, fireEventually
from foolscap.logging import log, flogfile
from foolscap.referenceable import SturdyRef
from foolscap.util import format_time, FORMAT_TIME_MODES, ensure_dict_str, ensure_dict_str_keys
from .interfaces import RILogObserver
        else:
            self.formatted_print(d)
        if self.saver:
            self.saver.remote_msg(d)

    def simple_print(self, d):
        print(six.text_type(d), file=self.output)

    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)


class LogTail:
    def __init__(self, options):
        self.options = options

    def run(self, target_furl):
        target_tubid = SturdyRef(target_furl).getTubRef().getTubID()

# Path: src/foolscap/logging/interfaces.py
# class RILogObserver(RemoteInterface):
#     __remote_name__ = "RILogObserver.foolscap.lothar.com"
#     def msg(logmsg=Event):
#         return None
#     def done():
#         return None
# 
#     def new_incident(name=Any(), trigger=Event):
#         # should this give (tubid, incarnation, trigger) like list_incidents?
#         return None
#     def done_with_incident_catchup():
#         return None


# Path: src/foolscap/logging/tail.py
import six, os, sys, time
from zope.interface import implementer
from twisted.internet import reactor
from twisted.python import usage
from foolscap import base32
from foolscap.api import Tub, Referenceable, fireEventually
from foolscap.logging import log, flogfile
from foolscap.referenceable import SturdyRef
from foolscap.util import format_time, FORMAT_TIME_MODES, ensure_dict_str, ensure_dict_str_keys
from .interfaces import RILogObserver

        else:
            self.formatted_print(d)
        if self.saver:
            self.saver.remote_msg(d)

    def simple_print(self, d):
        print(six.text_type(d), file=self.output)

    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)


class LogTail:
    def __init__(self, options):
        self.options = options

    def run(self, target_furl):
        target_tubid = SturdyRef(target_furl).getTubRef().getTubID()

        d = fireEventually(target_furl)