From aacdbcb0d190b198c6f37c081d3a2239f42ff9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 25 Mar 2018 16:06:59 +0200 Subject: [PATCH] Standardize log constant naming and declaration placement --- lib/tfw/components/directory_monitor.py | 5 +++-- .../directory_monitoring_event_handler.py | 7 ++++--- .../components/process_managing_event_handler.py | 5 +++-- lib/tfw/components/source_code_event_handler.py | 13 +++++++------ lib/tfw/components/terminado_event_handler.py | 7 ++++--- lib/tfw/components/terminado_mini_server.py | 5 +++-- .../networking/server/event_handler_connector.py | 7 ++++--- lib/tfw/networking/server/tfw_server.py | 7 ++++--- lib/tfw/networking/server/zmq_websocket_handler.py | 11 ++++++----- 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/tfw/components/directory_monitor.py b/lib/tfw/components/directory_monitor.py index 645db89..2c222d1 100644 --- a/lib/tfw/components/directory_monitor.py +++ b/lib/tfw/components/directory_monitor.py @@ -7,7 +7,8 @@ from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.components.decorators import RateLimiter from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class DirectoryMonitor: @@ -64,7 +65,7 @@ class WebideReloadWatchdogEventHandler(FileSystemWatchdogEventHandler): if self.ignore > 0: self.ignore = self.ignore - 1 return - log.debug(event) + LOG.debug(event) key = 'webide' self.uplink.send(key, {'data': {'command': 'reload'}}) diff --git a/lib/tfw/components/directory_monitoring_event_handler.py b/lib/tfw/components/directory_monitoring_event_handler.py index afceaaf..06b5450 100644 --- a/lib/tfw/components/directory_monitoring_event_handler.py +++ b/lib/tfw/components/directory_monitoring_event_handler.py @@ -3,7 +3,8 @@ from os.path import isdir, exists from tfw.components.directory_monitor import DirectoryMonitor from tfw.event_handler_base import TriggerlessEventHandler from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class DirectoryMonitoringEventHandler(TriggerlessEventHandler): @@ -42,7 +43,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler): message['data'] = self.commands[message['data']['command']](message['data']) return message except KeyError: - log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) + LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) def pause(self, data): self.monitor.pause() @@ -62,7 +63,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler): self.reload_monitor() return data except EnvironmentError: - log.error('Failed to switch directory!') + LOG.error('Failed to switch directory!') def cleanup(self): self.monitor.stop() diff --git a/lib/tfw/components/process_managing_event_handler.py b/lib/tfw/components/process_managing_event_handler.py index 7ceb623..cab3fea 100644 --- a/lib/tfw/components/process_managing_event_handler.py +++ b/lib/tfw/components/process_managing_event_handler.py @@ -4,7 +4,8 @@ from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.mixins import SupervisorMixin from tfw.components.directory_monitor import with_monitor_paused from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class ProcessManager(SupervisorMixin): @@ -32,7 +33,7 @@ class ProcessManagingEventHandler(TriggerlessEventHandler): self.processmanager(data['command'], data['process_name']) return message except KeyError: - log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) + LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) except SupervisorFault as fault: message['data']['error'] = fault.faultString message['data']['log'] = self.processmanager.read_log(message['data']['process_name']) diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 6e3bec0..8e795da 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -6,7 +6,8 @@ from collections import Iterable from tfw.event_handler_base import TriggerlessEventHandler from tfw.components.directory_monitor import DirectoryMonitor from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class FileManager: @@ -103,13 +104,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler): def write(self, data): self.monitor.ignore = self.monitor.ignore + 1 try: self.filemanager.file_contents = data['content'] - except Exception: log.exception('Error writing file!') + except Exception: LOG.exception('Error writing file!') del data['content'] return data def select(self, data): try: self.filemanager.filename = data['filename'] - except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename'])) + except EnvironmentError: LOG.exception('Failed to select file "{}"'.format(data['filename'])) return data def select_dir(self, data): @@ -122,12 +123,12 @@ class SourceCodeEventHandler(TriggerlessEventHandler): except IndexError: data['content'] = 'No files in this directory :(' except EnvironmentError: - log.error('Failed to select directory "{}"'.format(data['directory'])) + LOG.error('Failed to select directory "{}"'.format(data['directory'])) return data def exclude(self, data): try: self.filemanager.exclude = list(data['exclude']) - except TypeError: log.error('Exclude must be Iterable!') + except TypeError: LOG.error('Exclude must be Iterable!') return data def attach_fileinfo(self, data): @@ -142,7 +143,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler): self.attach_fileinfo(data) return message except KeyError: - log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) + LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) def cleanup(self): self.monitor.stop() diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 6e1b1b5..d743b09 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -3,7 +3,8 @@ from tfw.components.history_monitor import HistoryMonitor from tfw.event_handler_base import TriggerlessEventHandler from tfw.config import tfwenv from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class TerminadoEventHandler(TriggerlessEventHandler): @@ -22,12 +23,12 @@ class TerminadoEventHandler(TriggerlessEventHandler): return self._historymonitor def handle_event(self, key, message): - log.debug('TerminadoEventHandler received event: {}'.format(message)) + LOG.debug('TerminadoEventHandler received event: {}'.format(message)) try: message['data'] = self.commands[message['data']['command']](message['data']) return message except KeyError: - log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) + LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) def write(self, data): self.terminado_server.pty.write(data['shellcmd']) diff --git a/lib/tfw/components/terminado_mini_server.py b/lib/tfw/components/terminado_mini_server.py index 153a382..e3c08c2 100644 --- a/lib/tfw/components/terminado_mini_server.py +++ b/lib/tfw/components/terminado_mini_server.py @@ -4,7 +4,8 @@ from terminado import TermSocket, SingleTermManager from tfw.config import tfwenv from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class TerminadoMiniServer: @@ -41,6 +42,6 @@ class TerminadoMiniServer: if __name__ == '__main__': - log.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT)) + LOG.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT)) TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen() IOLoop.instance().start() diff --git a/lib/tfw/networking/server/event_handler_connector.py b/lib/tfw/networking/server/event_handler_connector.py index b01d7c3..ca741e6 100644 --- a/lib/tfw/networking/server/event_handler_connector.py +++ b/lib/tfw/networking/server/event_handler_connector.py @@ -5,7 +5,8 @@ from tfw.networking.zmq_connector_base import ZMQConnectorBase from tfw.networking.serialization import serialize_all from tfw.config import tfwenv from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class EventHandlerDownlinkConnector(ZMQConnectorBase): @@ -15,7 +16,7 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase): self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket) address = 'tcp://*:{}'.format(tfwenv.RECEIVER_PORT) self._zmq_pull_socket.bind(address) - log.debug('Pull socket bound to {}'.format(address)) + LOG.debug('Pull socket bound to {}'.format(address)) class EventHandlerUplinkConnector(ZMQConnectorBase): @@ -24,7 +25,7 @@ class EventHandlerUplinkConnector(ZMQConnectorBase): self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB) address = 'tcp://*:{}'.format(tfwenv.PUBLISHER_PORT) self._zmq_pub_socket.bind(address) - log.debug('Pub socket bound to {}'.format(address)) + LOG.debug('Pub socket bound to {}'.format(address)) class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector): diff --git a/lib/tfw/networking/server/tfw_server.py b/lib/tfw/networking/server/tfw_server.py index c0ad6eb..37c1643 100644 --- a/lib/tfw/networking/server/tfw_server.py +++ b/lib/tfw/networking/server/tfw_server.py @@ -6,7 +6,8 @@ from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.message_sender import MessageSender from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class TFWServer: @@ -33,7 +34,7 @@ class TFWServer: def make_response(self, message): trigger = message.get('trigger', '') try: self._fsm_manager.trigger(trigger, message) - except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) + except AttributeError: LOG.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) return message def proxy_filter(self, message): @@ -62,7 +63,7 @@ class FSMManager: if all(predicate_results): try: self.fsm.trigger(trigger, message=message) - except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) + except AttributeError: LOG.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) def subscribe_predicate(self, trigger, *predicates): self.trigger_predicates[trigger].extend(predicates) diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index 100c515..c6bd38c 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -5,7 +5,8 @@ from tornado.websocket import WebSocketHandler from tfw.networking.serialization import deserialize_all from tfw.networking.server.event_handler_connector import EventHandlerConnector from tfw.config.logs import logging -log = logging.getLogger(__name__) + +LOG = logging.getLogger(__name__) class ZMQWebSocketHandler(WebSocketHandler): @@ -19,7 +20,7 @@ class ZMQWebSocketHandler(WebSocketHandler): ZMQWebSocketHandler.instances.remove(self) def open(self, *args, **kwargs): - log.debug('WebSocket connection initiated') + LOG.debug('WebSocket connection initiated') self._event_handler_connector.register_callback(self.zmq_callback) @classmethod @@ -27,13 +28,13 @@ class ZMQWebSocketHandler(WebSocketHandler): keyhandlers = {'mirror': cls.mirror} key, data = deserialize_all(*msg_parts) - log.debug('Received on pull socket: {}'.format(data)) + LOG.debug('Received on pull socket: {}'.format(data)) if key not in keyhandlers: for instance in cls.instances: instance.write_message(data) else: try: keyhandlers[key](data['data']) - except KeyError: log.error('Invalid mirror message format! Ignoring.') + except KeyError: LOG.error('Invalid mirror message format! Ignoring.') @classmethod def mirror(cls, data): @@ -41,7 +42,7 @@ class ZMQWebSocketHandler(WebSocketHandler): cls._event_handler_connector.send_message({'data': data}, key) def on_message(self, message): - log.debug('Received on WebSocket: {}'.format(message)) + LOG.debug('Received on WebSocket: {}'.format(message)) self.send_message(self.make_response(message)) def make_response(self, message):