How to use the txaio.make_logger function in txaio

To help you get started, we’ve selected a few txaio 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 crossbario / txaio / test / test_logging.py View on Github external
def __init__(self):
            self.log = txaio.make_logger()
github Kitware / VTK / ThirdParty / AutobahnPython / vtkAutobahn / autobahn / asyncio / component.py View on Github external
each component yourself.

    :param components: the Component(s) you wish to run
    :type components: Component or list of Components

    :param log_level: a valid log-level (or None to avoid calling start_logging)
    :type log_level: string
    """

    # actually, should we even let people "not start" the logging? I'm
    # not sure that's wise... (double-check: if they already called
    # txaio.start_logging() what happens if we call it again?)
    if log_level is not None:
        txaio.start_logging(level=log_level)
    loop = asyncio.get_event_loop()
    log = txaio.make_logger()

    # see https://github.com/python/asyncio/issues/341 asyncio has
    # "odd" handling of KeyboardInterrupt when using Tasks (as
    # run_until_complete does). Another option is to just resture
    # default SIGINT handling, which is to exit:
    #   import signal
    #   signal.signal(signal.SIGINT, signal.SIG_DFL)

    @asyncio.coroutine
    def exit():
        return loop.stop()

    def nicely_exit(signal):
        log.info("Shutting down due to {signal}", signal=signal)
        for task in asyncio.Task.all_tasks():
            task.cancel()
github crossbario / autobahn-python / autobahn / xbr / _buyer.py View on Github external
"""

        :param market_maker_adr:
        :type market_maker_adr:

        :param buyer_key: Consumer delegate (buyer) private Ethereum key.
        :type buyer_key: bytes

        :param max_price: Maximum price we are willing to buy per key.
        :type max_price: int
        """
        assert type(market_maker_adr) == bytes and len(market_maker_adr) == 20, 'market_maker_adr must be bytes[20], but got "{}"'.format(market_maker_adr)
        assert type(buyer_key) == bytes and len(buyer_key) == 32, 'buyer delegate must be bytes[32], but got "{}"'.format(buyer_key)
        assert type(max_price) == int and max_price > 0

        self.log = txaio.make_logger()

        # market maker address
        self._market_maker_adr = market_maker_adr

        # buyer delegate raw ethereum private key (32 bytes)
        self._pkey_raw = buyer_key

        # buyer delegate ethereum private key object
        self._pkey = eth_keys.keys.PrivateKey(buyer_key)

        # buyer delegate ethereum private account from raw private key
        # FIXME
        # self._acct = Account.privateKeyToAccount(self._pkey)
        self._acct = None

        # buyer delegate ethereum account canonical address
github crossbario / txaio / examples / log_interop_twisted.py View on Github external
# THE SOFTWARE.
#
###############################################################################

import sys
import txaio

txaio.use_twisted()

from twisted import logger
from twisted.logger import ILogObserver
from zope.interface import provider

# some library you use is using txaio logging stuff
class Library(object):
    log = txaio.make_logger()

    def something(self):
        self.log.info("info log from library foo={foo}", foo='bar')
        self.log.debug("debug information")

# lets say you start your own observer
@provider(ILogObserver)
class Observer(object):
    def __init__(self):
        self._out = sys.stdout
    def __call__(self, event):
        self._out.write("Observe: {}\n".format(event))

lib = Library()
print("logging not started")
logger.globalLogBeginner.beginLoggingTo([Observer()])
github crossbario / crossbar / crossbar / worker / transport.py View on Github external
STATE_STARTING = 2
    STATE_STARTED = 3
    STATE_FAILED = 4
    STATE_STOPPING = 5
    STATE_STOPPED = 6

    STATES = {
        STATE_CREATED: "created",
        STATE_STARTING: "starting",
        STATE_STARTED: "started",
        STATE_FAILED: "failed",
        STATE_STOPPING: "stopping",
        STATE_STOPPED: "stopped",
    }

    log = make_logger()

    def __init__(self, worker, transport_id, config):
        """

        :param worker: The (router) worker session the transport is created from.
        :type worker: crossbar.worker.router.RouterController

        :param transport_id: The transport ID within the router.
        :type transport_id: str

        :param config: The transport's configuration.
        :type config: dict
        """
        self._worker = worker
        self._transport_id = transport_id
github crossbario / iotcookbook / device / pi / components / gamepad / app / client.py View on Github external
from twisted.internet.protocol import Protocol
from twisted.protocols.basic import LineReceiver
from twisted.internet.error import ReactorNotRunning

from autobahn.util import utcnow
from autobahn.twisted.util import sleep
from autobahn.wamp.types import PublishOptions
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
from autobahn.wamp.exception import ApplicationError


class XboxdrvReceiver(LineReceiver):
    """
    Protocol for parsing output from Xboxdrv.
    """
    log = txaio.make_logger()

    delimiter = b'\n'

    def __init__(self):
        self._session = None
        self._last = None

    def connectionMade(self):
        self.log.info('XboxdrvReceiver connected')

    def lineReceived(self, line):
        self.log.debug("XboxdrvReceiver line received: {line}", line=line)

        # Parse lines received from Xboxdrv. Lines look like:
        # X1:  -764 Y1:  4198  X2:   385 Y2:  3898  du:0 dd:0 dl:0 dr:0  back:0 guide:0 start:0  TL:0 TR:0  A:0 B:0 X:0 Y:0  LB:0 RB:0  LT:  0 RT:  0
        try:
github crossbario / crossbar / crossbar / router / dealer.py View on Github external
"""
    :returns: True if the session supports cancel
    """
    return (
        side in session._session_roles
        and session._session_roles[side]
        and session._session_roles[side].call_canceling
    )


class Dealer(object):
    """
    Basic WAMP dealer.
    """

    log = make_logger()

    def __init__(self, router, reactor, options=None):
        """

        :param router: The router this dealer is part of.
        :type router: Object that implements :class:`crossbar.router.interfaces.IRouter`.

        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.types.RouterOptions`.
        """
        self._router = router
        self._reactor = reactor
        self._cancel_timers = txaio.make_batched_timer(1)  # timeouts have to be integers anyway
        self._options = options or RouterOptions()

        # generator for WAMP request IDs
github crossbario / autobahn-python / autobahn / asyncio / rawsocket.py View on Github external
txaio.use_asyncio()

FRAME_TYPE_DATA = 0
FRAME_TYPE_PING = 1
FRAME_TYPE_PONG = 2

MAGIC_BYTE = 0x7F


class PrefixProtocol(asyncio.Protocol):

    prefix_format = '!L'
    prefix_length = struct.calcsize(prefix_format)
    max_length = 16 * 1024 * 1024
    max_length_send = max_length
    log = txaio.make_logger()  # @UndefinedVariable

    def connection_made(self, transport):
        self.transport = transport
        peer = transport.get_extra_info('peername')
        self.peer = peer2str(peer)
        self.log.debug('RawSocker Asyncio: Connection made with peer {peer}', peer=self.peer)
        self._buffer = b''
        self._header = None
        self._wait_closed = txaio.create_future()

    @property
    def is_closed(self):
        if hasattr(self, '_wait_closed'):
            return self._wait_closed
        else:
            f = txaio.create_future()
github Kitware / VTK / ThirdParty / AutobahnPython / vtkAutobahn / autobahn / twisted / wamp.py View on Github external
    @inlineCallbacks
    def onDisconnect(self):
        """
        Implements :func:`autobahn.wamp.interfaces.ISession.onDisconnect`
        """
        yield self.app._fire_signal('ondisconnect')


class Application(object):
    """
    A WAMP application. The application object provides a simple way of
    creating, debugging and running WAMP application components.
    """

    log = txaio.make_logger()

    def __init__(self, prefix=None):
        """

        :param prefix: The application URI prefix to use for procedures and topics,
           e.g. ``"com.example.myapp"``.
        :type prefix: unicode
        """
        self._prefix = prefix

        # procedures to be registered once the app session has joined the router/realm
        self._procs = []

        # event handler to be subscribed once the app session has joined the router/realm
        self._handlers = []
github crossbario / crossbar / crossbar / worker / controller.py View on Github external
from crossbar._util import term_print

__all__ = ('WorkerController',)


class WorkerController(NativeProcess):

    """
    A native Crossbar.io worker process. The worker will be connected
    to the node's management router running inside the node controller
    via WAMP-over-stdio.
    """

    WORKER_TYPE = 'native'

    log = make_logger()

    def __init__(self, config=None, reactor=None, personality=None):
        # base ctor
        NativeProcess.__init__(self, config=config, reactor=reactor, personality=personality)

        # Release (public) key
        self._release_pubkey = _read_release_key()

        # Node (private) key (as a string, in hex)
        node_key_hex = _read_node_key(self.config.extra.cbdir, private=True)['hex']
        privkey = nacl.signing.SigningKey(node_key_hex, encoder=nacl.encoding.HexEncoder)

        # WAMP-cryptosign signing key
        self._node_key = cryptosign.SigningKey(privkey)

    def onConnect(self):