mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 17:31:33 +00:00
Write process logs to console with a separate handler
This commit is contained in:
parent
552c9f5f93
commit
c84ac99141
@ -1,2 +1,3 @@
|
|||||||
from .frontend_proxy_handler import FrontendProxyHandler
|
from .frontend_proxy_handler import FrontendProxyHandler
|
||||||
|
from .console_logs_handler import ConsoleLogsHandler
|
||||||
from .message_sender import MessageSender
|
from .message_sender import MessageSender
|
||||||
|
19
tfw/components/frontend/console_logs_handler.py
Normal file
19
tfw/components/frontend/console_logs_handler.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ConsoleLogsHandler:
|
||||||
|
keys = ['process.log.new']
|
||||||
|
|
||||||
|
def __init__(self, *, stream):
|
||||||
|
self.stream = stream
|
||||||
|
|
||||||
|
def handle_event(self, message, connector):
|
||||||
|
try:
|
||||||
|
connector.send_message({
|
||||||
|
'key': 'console.write',
|
||||||
|
'value': message[self.stream]
|
||||||
|
})
|
||||||
|
except KeyError:
|
||||||
|
LOG.error('Invalid %s message received: %s', self.keys, message)
|
@ -3,18 +3,16 @@ from xmlrpc.client import Fault as SupervisorFault
|
|||||||
|
|
||||||
from tfw.internals.networking import Scope
|
from tfw.internals.networking import Scope
|
||||||
|
|
||||||
from .supervisor import ProcessManager, ProcessLogManager
|
from .supervisor import ProcessManager
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ProcessHandler(ProcessManager, ProcessLogManager):
|
class ProcessHandler(ProcessManager):
|
||||||
keys = ['process']
|
keys = ['process']
|
||||||
|
|
||||||
def __init__(self, *, supervisor_uri, log_tail=0):
|
def __init__(self, *, supervisor_uri):
|
||||||
ProcessManager.__init__(self, supervisor_uri)
|
ProcessManager.__init__(self, supervisor_uri)
|
||||||
ProcessLogManager.__init__(self, supervisor_uri)
|
|
||||||
self.log_tail = log_tail
|
|
||||||
|
|
||||||
self.commands = {
|
self.commands = {
|
||||||
'process.start': self.start_process,
|
'process.start': self.start_process,
|
||||||
@ -28,15 +26,6 @@ class ProcessHandler(ProcessManager, ProcessLogManager):
|
|||||||
self.commands[message['key']](message['name'])
|
self.commands[message['key']](message['name'])
|
||||||
except SupervisorFault as fault:
|
except SupervisorFault as fault:
|
||||||
message['error'] = fault.faultString
|
message['error'] = fault.faultString
|
||||||
finally:
|
|
||||||
message['stdout'] = self.read_stdout(
|
|
||||||
message['name'],
|
|
||||||
self.log_tail
|
|
||||||
)
|
|
||||||
message['stderr'] = self.read_stderr(
|
|
||||||
message['name'],
|
|
||||||
self.log_tail
|
|
||||||
)
|
|
||||||
connector.send_message(message, scope=Scope.WEBSOCKET)
|
connector.send_message(message, scope=Scope.WEBSOCKET)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if not message['key'].startswith('process.log'):
|
if not message['key'].startswith('process.log'):
|
||||||
|
Loading…
Reference in New Issue
Block a user