mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 17:11:32 +00:00
Rework log deletion – use log_tail arguments instead
This commit is contained in:
parent
4815b97200
commit
28c16e1127
@ -12,10 +12,10 @@ from tfw.mixins import ObserverMixin, SupervisorLogMixin
|
|||||||
|
|
||||||
|
|
||||||
class LogMonitor(ObserverMixin):
|
class LogMonitor(ObserverMixin):
|
||||||
def __init__(self, process_name):
|
def __init__(self, process_name, log_tail=0):
|
||||||
self.prevent_log_recursion()
|
self.prevent_log_recursion()
|
||||||
ObserverMixin.__init__(self)
|
ObserverMixin.__init__(self)
|
||||||
event_handler = SendLogWatchdogEventHandler(process_name)
|
event_handler = SendLogWatchdogEventHandler(process_name, log_tail=log_tail)
|
||||||
self.observer.schedule(
|
self.observer.schedule(
|
||||||
event_handler,
|
event_handler,
|
||||||
event_handler.path
|
event_handler.path
|
||||||
@ -28,12 +28,13 @@ class LogMonitor(ObserverMixin):
|
|||||||
|
|
||||||
|
|
||||||
class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin):
|
class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin):
|
||||||
def __init__(self, process_name):
|
def __init__(self, process_name, log_tail=0):
|
||||||
self.threadlocalise_supervisor_instance()
|
self.threadlocalise_supervisor_instance()
|
||||||
self.process_name = process_name
|
self.process_name = process_name
|
||||||
self.procinfo = self.supervisor.getProcessInfo(self.process_name)
|
self.procinfo = self.supervisor.getProcessInfo(self.process_name)
|
||||||
super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']])
|
super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']])
|
||||||
self.uplink = ServerUplinkConnector()
|
self.uplink = ServerUplinkConnector()
|
||||||
|
self.log_tail = log_tail
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
@ -45,7 +46,7 @@ class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, Superviso
|
|||||||
'key': 'processlog',
|
'key': 'processlog',
|
||||||
'data': {
|
'data': {
|
||||||
'command': 'new_log',
|
'command': 'new_log',
|
||||||
'stdout': self.read_stdout(self.process_name),
|
'stdout': self.read_stdout(self.process_name, tail=self.log_tail),
|
||||||
'stderr': self.read_stderr(self.process_name)
|
'stderr': self.read_stderr(self.process_name, tail=self.log_tail)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -34,11 +34,12 @@ class ProcessManagingEventHandler(EventHandlerBase):
|
|||||||
Commands available: start, stop, restart, readlog
|
Commands available: start, stop, restart, readlog
|
||||||
(the names are as self-documenting as it gets)
|
(the names are as self-documenting as it gets)
|
||||||
"""
|
"""
|
||||||
def __init__(self, key, dirmonitor=None):
|
def __init__(self, key, dirmonitor=None, log_tail=0):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
self.key = key
|
self.key = key
|
||||||
self.monitor = dirmonitor
|
self.monitor = dirmonitor
|
||||||
self.processmanager = ProcessManager()
|
self.processmanager = ProcessManager()
|
||||||
|
self.log_tail = log_tail
|
||||||
|
|
||||||
@with_monitor_paused
|
@with_monitor_paused
|
||||||
def handle_event(self, message):
|
def handle_event(self, message):
|
||||||
@ -49,9 +50,8 @@ class ProcessManagingEventHandler(EventHandlerBase):
|
|||||||
except SupervisorFault as fault:
|
except SupervisorFault as fault:
|
||||||
message['data']['error'] = fault.faultString
|
message['data']['error'] = fault.faultString
|
||||||
finally:
|
finally:
|
||||||
message['data']['stdout'] = self.processmanager.read_stdout(data['process_name'])
|
message['data']['stdout'] = self.processmanager.read_stdout(data['process_name'], self.log_tail)
|
||||||
message['data']['stderr'] = self.processmanager.read_stderr(data['process_name'])
|
message['data']['stderr'] = self.processmanager.read_stderr(data['process_name'], self.log_tail)
|
||||||
self.processmanager.clear_logs(data['process_name'])
|
|
||||||
return message
|
return message
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)
|
||||||
|
@ -37,11 +37,11 @@ class SupervisorMixin(SupervisorBaseMixin):
|
|||||||
|
|
||||||
|
|
||||||
class SupervisorLogMixin(SupervisorBaseMixin):
|
class SupervisorLogMixin(SupervisorBaseMixin):
|
||||||
def read_stdout(self, process_name):
|
def read_stdout(self, process_name, tail=0):
|
||||||
return self.supervisor.readProcessStdoutLog(process_name, 0, 0)
|
return self.supervisor.readProcessStdoutLog(process_name, -tail, 0)
|
||||||
|
|
||||||
def read_stderr(self, process_name):
|
def read_stderr(self, process_name, tail=0):
|
||||||
return self.supervisor.readProcessStderrLog(process_name, 0, 0)
|
return self.supervisor.readProcessStderrLog(process_name, -tail, 0)
|
||||||
|
|
||||||
def clear_logs(self, process_name):
|
def clear_logs(self, process_name):
|
||||||
for logfile in ('stdout_logfile', 'stderr_logfile'):
|
for logfile in ('stdout_logfile', 'stderr_logfile'):
|
||||||
|
Loading…
Reference in New Issue
Block a user