class SystemdJournalNode(WatchNode): def __init__(self, log_type, api, journalctl_args): """ Arguments: log_type: name to give the log api: api for interacting with the proxy journalctl_args: a sequence of arguments to pass to journalctl, for example: ['--unit=ssh.service', 'SYSLOG_FACILITY=10'] """ self.unit_name = log_type super(SystemdJournalNode, self).__init__(log_type, api) self.command_args = ['journalctl', '-f', '--lines=1'] + journalctl_args self._start_follower() def cleanup(self): self.follower.cleanup() def _start_follower(self): self.follower = CommandOutputFollower(self.command_args) self.follower.start_process() def check_data(self, now): if not self.follower.check_process(): self.cleanup() self._start_follower() data = [] while True: line = self.follower.read_line(0.1) if line is None: break data.append(line) self.flush_data(data, now, compress=True)
def _start_follower(self): self.follower = CommandOutputFollower(self.command_args) self.follower.start_process()