Standardize log constant naming and declaration placement

This commit is contained in:
Kristóf Tóth 2018-03-25 16:06:59 +02:00
parent 1e2ea0ed17
commit aacdbcb0d1
9 changed files with 38 additions and 29 deletions

View File

@ -7,7 +7,8 @@ from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.components.decorators import RateLimiter from tfw.components.decorators import RateLimiter
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class DirectoryMonitor: class DirectoryMonitor:
@ -64,7 +65,7 @@ class WebideReloadWatchdogEventHandler(FileSystemWatchdogEventHandler):
if self.ignore > 0: if self.ignore > 0:
self.ignore = self.ignore - 1 self.ignore = self.ignore - 1
return return
log.debug(event) LOG.debug(event)
key = 'webide' key = 'webide'
self.uplink.send(key, {'data': {'command': 'reload'}}) self.uplink.send(key, {'data': {'command': 'reload'}})

View File

@ -3,7 +3,8 @@ from os.path import isdir, exists
from tfw.components.directory_monitor import DirectoryMonitor from tfw.components.directory_monitor import DirectoryMonitor
from tfw.event_handler_base import TriggerlessEventHandler from tfw.event_handler_base import TriggerlessEventHandler
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class DirectoryMonitoringEventHandler(TriggerlessEventHandler): class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
@ -42,7 +43,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
message['data'] = self.commands[message['data']['command']](message['data']) message['data'] = self.commands[message['data']['command']](message['data'])
return message return message
except KeyError: except KeyError:
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
def pause(self, data): def pause(self, data):
self.monitor.pause() self.monitor.pause()
@ -62,7 +63,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
self.reload_monitor() self.reload_monitor()
return data return data
except EnvironmentError: except EnvironmentError:
log.error('Failed to switch directory!') LOG.error('Failed to switch directory!')
def cleanup(self): def cleanup(self):
self.monitor.stop() self.monitor.stop()

View File

@ -4,7 +4,8 @@ from tfw.event_handler_base import TriggerlessEventHandler
from tfw.components.mixins import SupervisorMixin from tfw.components.mixins import SupervisorMixin
from tfw.components.directory_monitor import with_monitor_paused from tfw.components.directory_monitor import with_monitor_paused
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class ProcessManager(SupervisorMixin): class ProcessManager(SupervisorMixin):
@ -32,7 +33,7 @@ class ProcessManagingEventHandler(TriggerlessEventHandler):
self.processmanager(data['command'], data['process_name']) self.processmanager(data['command'], data['process_name'])
return message return message
except KeyError: except KeyError:
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
except SupervisorFault as fault: except SupervisorFault as fault:
message['data']['error'] = fault.faultString message['data']['error'] = fault.faultString
message['data']['log'] = self.processmanager.read_log(message['data']['process_name']) message['data']['log'] = self.processmanager.read_log(message['data']['process_name'])

View File

@ -6,7 +6,8 @@ from collections import Iterable
from tfw.event_handler_base import TriggerlessEventHandler from tfw.event_handler_base import TriggerlessEventHandler
from tfw.components.directory_monitor import DirectoryMonitor from tfw.components.directory_monitor import DirectoryMonitor
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class FileManager: class FileManager:
@ -103,13 +104,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
def write(self, data): def write(self, data):
self.monitor.ignore = self.monitor.ignore + 1 self.monitor.ignore = self.monitor.ignore + 1
try: self.filemanager.file_contents = data['content'] try: self.filemanager.file_contents = data['content']
except Exception: log.exception('Error writing file!') except Exception: LOG.exception('Error writing file!')
del data['content'] del data['content']
return data return data
def select(self, data): def select(self, data):
try: self.filemanager.filename = data['filename'] 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 return data
def select_dir(self, data): def select_dir(self, data):
@ -122,12 +123,12 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
except IndexError: except IndexError:
data['content'] = 'No files in this directory :(' data['content'] = 'No files in this directory :('
except EnvironmentError: except EnvironmentError:
log.error('Failed to select directory "{}"'.format(data['directory'])) LOG.error('Failed to select directory "{}"'.format(data['directory']))
return data return data
def exclude(self, data): def exclude(self, data):
try: self.filemanager.exclude = list(data['exclude']) 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 return data
def attach_fileinfo(self, data): def attach_fileinfo(self, data):
@ -142,7 +143,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
self.attach_fileinfo(data) self.attach_fileinfo(data)
return message return message
except KeyError: except KeyError:
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
def cleanup(self): def cleanup(self):
self.monitor.stop() self.monitor.stop()

View File

@ -3,7 +3,8 @@ from tfw.components.history_monitor import HistoryMonitor
from tfw.event_handler_base import TriggerlessEventHandler from tfw.event_handler_base import TriggerlessEventHandler
from tfw.config import tfwenv from tfw.config import tfwenv
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class TerminadoEventHandler(TriggerlessEventHandler): class TerminadoEventHandler(TriggerlessEventHandler):
@ -22,12 +23,12 @@ class TerminadoEventHandler(TriggerlessEventHandler):
return self._historymonitor return self._historymonitor
def handle_event(self, key, message): def handle_event(self, key, message):
log.debug('TerminadoEventHandler received event: {}'.format(message)) LOG.debug('TerminadoEventHandler received event: {}'.format(message))
try: try:
message['data'] = self.commands[message['data']['command']](message['data']) message['data'] = self.commands[message['data']['command']](message['data'])
return message return message
except KeyError: except KeyError:
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message)) LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
def write(self, data): def write(self, data):
self.terminado_server.pty.write(data['shellcmd']) self.terminado_server.pty.write(data['shellcmd'])

View File

@ -4,7 +4,8 @@ from terminado import TermSocket, SingleTermManager
from tfw.config import tfwenv from tfw.config import tfwenv
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class TerminadoMiniServer: class TerminadoMiniServer:
@ -41,6 +42,6 @@ class TerminadoMiniServer:
if __name__ == '__main__': 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() TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen()
IOLoop.instance().start() IOLoop.instance().start()

View File

@ -5,7 +5,8 @@ from tfw.networking.zmq_connector_base import ZMQConnectorBase
from tfw.networking.serialization import serialize_all from tfw.networking.serialization import serialize_all
from tfw.config import tfwenv from tfw.config import tfwenv
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class EventHandlerDownlinkConnector(ZMQConnectorBase): class EventHandlerDownlinkConnector(ZMQConnectorBase):
@ -15,7 +16,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(tfwenv.RECEIVER_PORT) address = 'tcp://*:{}'.format(tfwenv.RECEIVER_PORT)
self._zmq_pull_socket.bind(address) 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): class EventHandlerUplinkConnector(ZMQConnectorBase):
@ -24,7 +25,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(tfwenv.PUBLISHER_PORT) address = 'tcp://*:{}'.format(tfwenv.PUBLISHER_PORT)
self._zmq_pub_socket.bind(address) 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): class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):

View File

@ -6,7 +6,8 @@ from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
from tfw.message_sender import MessageSender from tfw.message_sender import MessageSender
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class TFWServer: class TFWServer:
@ -33,7 +34,7 @@ class TFWServer:
def make_response(self, message): def make_response(self, message):
trigger = message.get('trigger', '') trigger = message.get('trigger', '')
try: self._fsm_manager.trigger(trigger, message) 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 return message
def proxy_filter(self, message): def proxy_filter(self, message):
@ -62,7 +63,7 @@ class FSMManager:
if all(predicate_results): if all(predicate_results):
try: self.fsm.trigger(trigger, message=message) 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): def subscribe_predicate(self, trigger, *predicates):
self.trigger_predicates[trigger].extend(predicates) self.trigger_predicates[trigger].extend(predicates)

View File

@ -5,7 +5,8 @@ from tornado.websocket import WebSocketHandler
from tfw.networking.serialization import deserialize_all from tfw.networking.serialization import deserialize_all
from tfw.networking.server.event_handler_connector import EventHandlerConnector from tfw.networking.server.event_handler_connector import EventHandlerConnector
from tfw.config.logs import logging from tfw.config.logs import logging
log = logging.getLogger(__name__)
LOG = logging.getLogger(__name__)
class ZMQWebSocketHandler(WebSocketHandler): class ZMQWebSocketHandler(WebSocketHandler):
@ -19,7 +20,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
ZMQWebSocketHandler.instances.remove(self) ZMQWebSocketHandler.instances.remove(self)
def open(self, *args, **kwargs): def open(self, *args, **kwargs):
log.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)
@classmethod @classmethod
@ -27,13 +28,13 @@ class ZMQWebSocketHandler(WebSocketHandler):
keyhandlers = {'mirror': cls.mirror} keyhandlers = {'mirror': cls.mirror}
key, data = deserialize_all(*msg_parts) 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: if key not in keyhandlers:
for instance in cls.instances: for instance in cls.instances:
instance.write_message(data) instance.write_message(data)
else: else:
try: keyhandlers[key](data['data']) try: keyhandlers[key](data['data'])
except KeyError: log.error('Invalid mirror message format! Ignoring.') except KeyError: LOG.error('Invalid mirror message format! Ignoring.')
@classmethod @classmethod
def mirror(cls, data): def mirror(cls, data):
@ -41,7 +42,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
cls._event_handler_connector.send_message({'data': data}, key) cls._event_handler_connector.send_message({'data': data}, key)
def on_message(self, message): 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)) self.send_message(self.make_response(message))
def make_response(self, message): def make_response(self, message):