~mdkcore/jackplug

f1d40925538a939b45a814a1644ca3b2dfcbdaa1 — Rodrigo Oliveira 3 years ago 82db4a3
Add set_logger method on JackBase and PlugBase

This let us to externally configure the logger, or use another logging system
compatible with python logging.
5 files changed, 23 insertions(+), 20 deletions(-)

M .gitignore
M examples/jack.py
M examples/plug.py
M jackplug/jack.py
M jackplug/plug.py
M .gitignore => .gitignore +3 -0
@@ 4,4 4,7 @@
JackPlug.egg-info/
build/
dist/

.python-version
WORK-*
__pycache__

M examples/jack.py => examples/jack.py +1 -4
@@ 1,6 1,3 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2016 BYNE. All rights reserved.



@@ 71,5 68,5 @@ if __name__ == '__main__':
    elif use_tcp:
        endpoint = TCPEndpoint(address="127.0.0.1", port="1234")

    jack = JackTest(service=ident, endpoint=endpoint)
    jack = JackTest(service=ident.encode(), endpoint=endpoint)
    print("Exiting Jack...")

M examples/plug.py => examples/plug.py +0 -3
@@ 1,6 1,3 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2016 BYNE. All rights reserved.


M jackplug/jack.py => jackplug/jack.py +9 -7
@@ 1,6 1,3 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2016 BYNE. All rights reserved.



@@ 10,9 7,9 @@ We are calling ZMQ's 'identity' as 'service', to ease the understanding of
services.
"""

import logging
import signal
import uuid

import zmq
from zmq.utils import jsonapi
from zmq.eventloop import ioloop, zmqstream


@@ 20,9 17,7 @@ from zmq.eventloop import ioloop, zmqstream
from .utils import Configuration
from .utils import IPCEndpoint

from simb.pilsner import log as logging

log = logging.getLogger('Service')
log = logging.getLogger("JackPlug")


class JackBase(object):


@@ 82,6 77,13 @@ class JackBase(object):
        self.socket_stream.close()
        self.socket.close()

    @staticmethod
    def set_logger(logger):
        global log

        log.propagate = False
        log = logger

    def heartbeat(self):
        """Send a ping message to the other endpoint"""
        JackBase.send(self, {"event": "ping", "data": {'id': self._identity}})

M jackplug/plug.py => jackplug/plug.py +10 -6
@@ 1,6 1,3 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
Copyright (c) 2016 BYNE. All rights reserved.



@@ 10,9 7,10 @@ We are calling ZMQ's 'identity' as 'service', to ease the understanding of the
services.
"""

import time
import logging
import signal
import threading
import time

import zmq
from zmq.utils import jsonapi


@@ 21,9 19,8 @@ from zmq.eventloop import ioloop, zmqstream
from .utils import Configuration
from .utils import IPCEndpoint

from simb.pilsner import log as logging

log = logging.getLogger('Service')
log = logging.getLogger("JackPlug")


class PlugBase(object):


@@ 66,6 63,13 @@ class PlugBase(object):
        except Exception as e:
            log.error("An error occurred while closing socket: %s", e)

    @staticmethod
    def set_logger(logger):
        global log

        log.propagate = False
        log = logger

    def heartbeat(self):
        """Check if known jacks are alive (pinging us)"""
        services = list(self._services_ping.keys())