How to use the eliot.add_destination function in eliot

To help you get started, we’ve selected a few eliot 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 applied-mixnetworks / txmix / test / test_onion_mix.py View on Github external
from twisted.protocols.basic import Int32StringReceiver

from sphinxmixcrypto import SphinxParams, PacketReplayCacheDict

from txmix import OnionTransportFactory, ThresholdMixNode, IMixTransport, ContinuousTimeMixNode
from txmix.client import MixClient, RandomRouteFactory, CascadeRouteFactory
from txmix.onion_transport import OnionDatagramProxyFactory
from test_txmix import generate_node_id, generate_node_keypair, ChachaNoiseReader, MixKeyState, DummyPKI


# tell eliot to log a line of json for each message to stdout
def stdout(message):
    sys.stdout.write(json.dumps(message) + "\n")


add_destination(stdout)


@pytest.inlineCallbacks
def test_onion_datagram_proxy():
    received_buffer = []
    received_d = defer.Deferred()

    def received(data):
        received_buffer.append(data)
        received_d.callback(None)

    received_size = 10
    proxy_factory = OnionDatagramProxyFactory(received)
    protocol = proxy_factory.buildProtocol(123)
    packet = b"A" * received_size
    protocol.stringReceived(packet)
github LeastAuthority / txkube / src / txkube / testing / _eliot.py View on Github external
def _setUp(self):
        self.logs = []
        add_destination(self.logs.append)
        self.addCleanup(lambda: remove_destination(self.logs.append))
        self.addDetail(
            self.LOG_DETAIL_NAME,
            Content(
                UTF8_TEXT,
                lambda: [_eliottree(self.logs)],
            ),
github ClusterHQ / flocker / admin / client.py View on Github external
@inlineCallbacks
def main(reactor, args, base_path, top_level):
    """
    :param reactor: Reactor to use.
    :param list args: The arguments passed to the script.
    :param FilePath base_path: The executable being run.
    :param FilePath top_level: The top-level of the flocker repository.
    """
    options = RunOptions(top_level=top_level)

    add_destination(eliot_output)
    try:
        options.parseOptions(args)
    except UsageError as e:
        sys.stderr.write("%s: %s\n" % (base_path.basename(), e))
        raise SystemExit(1)

    runner = options.runner

    try:
        nodes = yield runner.start_nodes(reactor, node_count=1)
        yield perform(
            make_dispatcher(reactor),
            install_cli(runner.package_source, nodes[0]))
        result = yield run_client_tests(reactor=reactor, node=nodes[0])
    except:
        result = 1
github ClusterHQ / flocker / admin / acceptance.py View on Github external
@inlineCallbacks
def main(reactor, args, base_path, top_level):
    """
    :param reactor: Reactor to use.
    :param list args: The arguments passed to the script.
    :param FilePath base_path: The executable being run.
    :param FilePath top_level: The top-level of the flocker repository.
    """
    options = RunOptions(top_level=top_level)

    add_destination(eliot_output)
    try:
        options.parseOptions(args)
    except UsageError as e:
        sys.stderr.write("%s: %s\n" % (base_path.basename(), e))
        raise SystemExit(1)

    runner = options.runner

    from flocker.common.script import eliot_logging_service
    log_writer = eliot_logging_service(
        destination=FileDestination(
            file=open("%s.log" % (base_path.basename(),), "a")
        ),
        reactor=reactor,
        capture_stdout=False)
    log_writer.startService()
github ClusterHQ / flocker / admin / cluster_setup.py View on Github external
@inlineCallbacks
def main(reactor, args, base_path, top_level):
    """
    :param reactor: Reactor to use.
    :param list args: The arguments passed to the script.
    :param FilePath base_path: The executable being run.
    :param FilePath top_level: The top-level of the Flocker repository.
    """
    options = RunOptions(top_level=top_level)

    add_destination(eliot_output)
    try:
        options.parseOptions(args)
    except UsageError as e:
        sys.stderr.write("%s: %s\n" % (base_path.basename(), e))
        raise SystemExit(1)

    runner = options.runner

    def cluster_cleanup():
        print("stopping cluster")
        return runner.stop_cluster(reactor)

    cleanup_trigger_id = reactor.addSystemEventTrigger('before', 'shutdown',
                                                       cluster_cleanup)

    from flocker.common.script import eliot_logging_service
github dtag-dev-sec / explo / explo / core.py View on Github external
""" Load, validate and process blocks """

    if not content:
        raise ExploException('no exploitation content')

    try:
        blocks = load_blocks(content)
    except yaml.YAMLError as err:
        raise ExploException('error parsing document: %s' % err)

    if not validate_blocks(blocks):
        raise ExploException('error parsing document:' \
            'not all blocks specify the required fields %s' % FIELDS_REQUIRED)

    if log:
        add_destination(log)

    return process_blocks(blocks)
github LeastAuthority / leastauthority.com / src / lae_util / eliot_destination.py View on Github external
def startService(self):
        self.stdlib_cleanup = stdlib_logging_to_eliot_configuration(getLogger())
        self.twisted_observer = TwistedLoggerToEliotObserver()
        globalLogPublisher.addObserver(self.twisted_observer)

        for dest in self.destinations:
            add_destination(dest)
github ClusterHQ / flocker / flocker / common / script.py View on Github external
message_format = ''
        if message_type is not None:
            if message_type == 'twisted:log' and message.get('error'):
                message_format = '%(message)s'
            else:
                message_format = message_formats.get(message_type, '')
        elif action_type is not None:
            if action_status == 'started':
                message_format = action_formats.get('action_type', '')
            # We don't consider other status, since we
            # have no meaningful messages to write.
        stdout.write(message_format % message)
        stdout.flush()

    add_destination(eliot_output)