Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed May 20, 2020
1 parent d5a2efc commit 1db71f0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/labthings/server/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
return {"message": str(record.msg), "level": record.levelname.lower()}
11 changes: 9 additions & 2 deletions src/labthings/server/wsgi/gevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

sentinel = object()


class Server:
def __init__(
self,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 10 additions & 8 deletions src/labthings/server/wsgi/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down

0 comments on commit 1db71f0

Please sign in to comment.