mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:01:31 +00:00
Refactor logging
This commit is contained in:
parent
1856831d80
commit
071167d3d7
5
lib/config/logs.py
Normal file
5
lib/config/logs.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
# TODO: configure supervisord loglevel from here
|
@ -1,4 +1,3 @@
|
|||||||
import logging
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import tornado
|
import tornado
|
||||||
@ -7,6 +6,8 @@ from tornado.web import Application
|
|||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
from config import WEB_PORT
|
from config import WEB_PORT
|
||||||
|
from config.logs import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
from handlers import FSMManagingSocketHandler
|
from handlers import FSMManagingSocketHandler
|
||||||
from sql_injection_fsm import SQLInjectionFSM
|
from sql_injection_fsm import SQLInjectionFSM
|
||||||
|
|
||||||
@ -26,10 +27,9 @@ if __name__ == '__main__':
|
|||||||
)
|
)
|
||||||
|
|
||||||
application.listen(WEB_PORT)
|
application.listen(WEB_PORT)
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
log.debug('Python version: {}'.format(sys.version[:5]))
|
||||||
logging.debug('Python version: {}'.format(sys.version[:5]))
|
log.debug('Tornado version: {}'.format(tornado.version))
|
||||||
logging.debug('Tornado version: {}'.format(tornado.version))
|
log.debug('ZeroMQ version: {}'.format(zmq.zmq_version()))
|
||||||
logging.debug('ZeroMQ version: {}'.format(zmq.zmq_version()))
|
log.debug('PyZMQ version: {}'.format(zmq.pyzmq_version()))
|
||||||
logging.debug('PyZMQ version: {}'.format(zmq.pyzmq_version()))
|
log.info('Tornado application listening on port {}'.format(WEB_PORT))
|
||||||
logging.info('Tornado application listening on port {}'.format(WEB_PORT))
|
|
||||||
IOLoop.instance().start()
|
IOLoop.instance().start()
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
import zmq
|
import zmq
|
||||||
from zmq.eventloop import ioloop
|
from zmq.eventloop import ioloop
|
||||||
from zmq.eventloop.zmqstream import ZMQStream
|
from zmq.eventloop.zmqstream import ZMQStream
|
||||||
|
|
||||||
from config import PUBLISHER_PORT, RECEIVER_PORT
|
from config import PUBLISHER_PORT, RECEIVER_PORT
|
||||||
|
from config.logs import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
from util import parse_anchor_from_message, ZMQConnectorBase
|
from util import parse_anchor_from_message, ZMQConnectorBase
|
||||||
|
|
||||||
|
|
||||||
ioloop.install()
|
ioloop.install()
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
|||||||
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
|
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
|
||||||
address = 'tcp://*:{}'.format(RECEIVER_PORT)
|
address = 'tcp://*:{}'.format(RECEIVER_PORT)
|
||||||
self._zmq_pull_socket.bind(address)
|
self._zmq_pull_socket.bind(address)
|
||||||
logging.debug('Pull socket bound to {}'.format(address))
|
log.debug('Pull socket bound to {}'.format(address))
|
||||||
|
|
||||||
|
|
||||||
class EventHandlerUplinkConnector(ZMQConnectorBase):
|
class EventHandlerUplinkConnector(ZMQConnectorBase):
|
||||||
@ -26,7 +27,7 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
|
|||||||
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
|
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
|
||||||
address = 'tcp://*:{}'.format(PUBLISHER_PORT)
|
address = 'tcp://*:{}'.format(PUBLISHER_PORT)
|
||||||
self._zmq_pub_socket.bind(address)
|
self._zmq_pub_socket.bind(address)
|
||||||
logging.debug('Pub socket bound to {}'.format(address))
|
log.debug('Pub socket bound to {}'.format(address))
|
||||||
|
|
||||||
|
|
||||||
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import logging
|
|
||||||
import json
|
import json
|
||||||
from tornado.websocket import WebSocketHandler
|
from tornado.websocket import WebSocketHandler
|
||||||
from util import parse_anchor_from_message
|
from util import parse_anchor_from_message
|
||||||
|
|
||||||
from event_handler_connector import EventHandlerConnector
|
from event_handler_connector import EventHandlerConnector
|
||||||
|
from config.logs import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ZMQWebSocketHandler(WebSocketHandler):
|
class ZMQWebSocketHandler(WebSocketHandler):
|
||||||
@ -13,16 +14,16 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
|||||||
super().__init__(application, request, **kwargs)
|
super().__init__(application, request, **kwargs)
|
||||||
|
|
||||||
def open(self, *args, **kwargs):
|
def open(self, *args, **kwargs):
|
||||||
logging.debug('WebSocket connection initiated')
|
log.debug('WebSocket connection initiated')
|
||||||
self._event_handler_connector.register_callback(self.zmq_callback)
|
self._event_handler_connector.register_callback(self.zmq_callback)
|
||||||
|
|
||||||
def zmq_callback(self, msg_parts):
|
def zmq_callback(self, msg_parts):
|
||||||
anchor, data = msg_parts
|
anchor, data = msg_parts
|
||||||
logging.debug('Received on pull socket: {}'.format(data.decode()))
|
log.debug('Received on pull socket: {}'.format(data.decode()))
|
||||||
self.write_message(data.decode())
|
self.write_message(data.decode())
|
||||||
|
|
||||||
def on_message(self, message):
|
def on_message(self, message):
|
||||||
logging.debug('Received on WebSocket: {}'.format(message))
|
log.debug('Received on WebSocket: {}'.format(message))
|
||||||
self.send_message(*self.make_response(message))
|
self.send_message(*self.make_response(message))
|
||||||
|
|
||||||
def make_response(self, message):
|
def make_response(self, message):
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import logging
|
|
||||||
from shutil import rmtree, copytree
|
from shutil import rmtree, copytree
|
||||||
|
|
||||||
from event_handler_base import EventHandlerBase
|
from event_handler_base import EventHandlerBase
|
||||||
from util import SupervisorMixin
|
from util import SupervisorMixin
|
||||||
from config import TERMINADO_DIR
|
from config import TERMINADO_DIR
|
||||||
|
from config.logs import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
||||||
@ -19,5 +20,5 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
|
|||||||
self.supervisor.startProcess(self.process_name)
|
self.supervisor.startProcess(self.process_name)
|
||||||
|
|
||||||
def handle_event(self, anchor, data_json):
|
def handle_event(self, anchor, data_json):
|
||||||
logging.debug('TerminadoEventHandler received event for anchor {}'.format(anchor))
|
log.debug('TerminadoEventHandler received event for anchor {}'.format(anchor))
|
||||||
# TODO: wat do?
|
# TODO: wat do?
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import logging
|
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
from tornado.web import Application
|
from tornado.web import Application
|
||||||
from terminado import TermSocket, UniqueTermManager
|
from terminado import TermSocket, UniqueTermManager
|
||||||
|
|
||||||
from config import TERMINADO_PORT, TERMINADO_WD
|
from config import TERMINADO_PORT, TERMINADO_WD
|
||||||
|
from config.logs import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TerminadoMiniServer:
|
class TerminadoMiniServer:
|
||||||
@ -28,6 +29,5 @@ class TerminadoMiniServer:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
log.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
|
||||||
logging.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
|
|
||||||
TerminadoMiniServer('/terminal', TERMINADO_PORT, TERMINADO_WD, ['bash']).listen()
|
TerminadoMiniServer('/terminal', TERMINADO_PORT, TERMINADO_WD, ['bash']).listen()
|
||||||
|
Loading…
Reference in New Issue
Block a user