2019-08-23 13:27:03 +00:00
|
|
|
from tfw.internals.networking import Scope, Intent
|
2019-07-24 13:17:16 +00:00
|
|
|
from tfw.internals.inotify import InotifyObserver
|
2019-07-05 13:25:59 +00:00
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
from .supervisor import ProcessLogManager
|
2019-07-05 13:25:59 +00:00
|
|
|
|
|
|
|
|
2019-07-24 13:17:16 +00:00
|
|
|
class LogInotifyObserver(InotifyObserver, ProcessLogManager):
|
2019-08-07 07:47:57 +00:00
|
|
|
def __init__(self, connector, process_name, supervisor_uri, log_tail=0):
|
2019-07-30 13:17:29 +00:00
|
|
|
self._connector = connector
|
2019-07-05 13:25:59 +00:00
|
|
|
self._process_name = process_name
|
|
|
|
self.log_tail = log_tail
|
|
|
|
self._procinfo = None
|
2019-07-24 13:17:16 +00:00
|
|
|
ProcessLogManager.__init__(self, supervisor_uri)
|
2019-07-05 13:25:59 +00:00
|
|
|
InotifyObserver.__init__(self, self._get_logfiles())
|
|
|
|
|
|
|
|
def _get_logfiles(self):
|
|
|
|
self._procinfo = self.supervisor.getProcessInfo(self._process_name)
|
|
|
|
return self._procinfo['stdout_logfile'], self._procinfo['stderr_logfile']
|
|
|
|
|
|
|
|
@property
|
|
|
|
def process_name(self):
|
|
|
|
return self._process_name
|
|
|
|
|
|
|
|
@process_name.setter
|
|
|
|
def process_name(self, process_name):
|
|
|
|
self._process_name = process_name
|
|
|
|
self.paths = self._get_logfiles()
|
|
|
|
|
|
|
|
def on_modified(self, event):
|
2019-07-30 13:17:29 +00:00
|
|
|
self._connector.send_message({
|
2019-08-08 12:45:59 +00:00
|
|
|
'key': 'process.log.new',
|
2019-08-07 07:47:57 +00:00
|
|
|
'stdout': self.read_stdout(self.process_name, tail=self.log_tail),
|
|
|
|
'stderr': self.read_stderr(self.process_name, tail=self.log_tail)
|
2019-08-23 13:27:03 +00:00
|
|
|
}, Scope.BROADCAST, Intent.EVENT)
|