From 1db71f00b8c5f57a4dd626d2c81d551c1aba8fab Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Wed, 20 May 2020 17:38:01 +0100 Subject: [PATCH] Formatted code --- src/labthings/server/logging.py | 2 +- src/labthings/server/wsgi/gevent.py | 11 +++++++++-- src/labthings/server/wsgi/handler.py | 18 ++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/labthings/server/logging.py b/src/labthings/server/logging.py index b1527fa6..a81c8da5 100644 --- a/src/labthings/server/logging.py +++ b/src/labthings/server/logging.py @@ -15,4 +15,4 @@ def emit(self, record): current_labthing().emit("logging", log_event) def rest_format_record(self, record): - return {"message": str(record.msg), "level": record.levelname.lower()} \ No newline at end of file + return {"message": str(record.msg), "level": record.levelname.lower()} diff --git a/src/labthings/server/wsgi/gevent.py b/src/labthings/server/wsgi/gevent.py index 91760f19..e60d9492 100644 --- a/src/labthings/server/wsgi/gevent.py +++ b/src/labthings/server/wsgi/gevent.py @@ -11,6 +11,7 @@ sentinel = object() + class Server: def __init__( self, @@ -136,7 +137,7 @@ def start(self): app_to_run, handler_class=WebSocketHandler, log=self.log, - error_log=self.error_log + error_log=self.error_log, ) # Serve @@ -153,7 +154,13 @@ def start(self): self.stop() # pragma: no cover def run( - self, host=None, port=None, log=sentinel, error_log=sentinel, debug=None, zeroconf=None, + self, + host=None, + port=None, + log=sentinel, + error_log=sentinel, + debug=None, + zeroconf=None, ): """Starts the server allowing for runtime parameters. Designed to immitate the old Flask app.run style of starting an app diff --git a/src/labthings/server/wsgi/handler.py b/src/labthings/server/wsgi/handler.py index 18ac36c3..0027009e 100644 --- a/src/labthings/server/wsgi/handler.py +++ b/src/labthings/server/wsgi/handler.py @@ -2,23 +2,25 @@ from logging import getLogger, StreamHandler, getLoggerClass, Formatter, DEBUG + def create_logger(name, handlers=None, debug=False): - if not handlers: - handlers = () + if not handlers: + handlers = () + + logger = getLogger(name) - logger = getLogger(name) + for handler in handlers: + logger.addHandler(handler) - for handler in handlers: - logger.addHandler(handler) + return logger - return logger class WebSocketHandler(_WebSocketHandler): @property def logger(self): if not hasattr(self, "_logger"): - if hasattr(self.server, 'log'): - self._logger = create_logger(__name__, handlers=(self.server.log, )) + if hasattr(self.server, "log"): + self._logger = create_logger(__name__, handlers=(self.server.log,)) else: self._logger = create_logger(__name__)