def __init__(self, log, sender, tags, *args, **kwargs): if isinstance(log, FileObject): self.log = log else: self.log = FileObject(log) self.tags = tags self.sender = sender super(ProcessSingleFile, self).__init__(*args, **kwargs)
def __tail_log(self, log_path): file = open(log_path, 'r') st_results = os.stat(log_path) st_size = st_results[6] file.seek(st_size) return FileObject(file)
class ProcessSingleFile(pyinotify.ProcessEvent): def __init__(self, log, sender, tags, *args, **kwargs): if isinstance(log, FileObject): self.log = log else: self.log = FileObject(log) self.tags = tags self.sender = sender super(ProcessSingleFile, self).__init__(*args, **kwargs) def process_IN_MODIFY(self, event): for line in self.log.read_line(): self.sender.captureMessage(line, tags=self.tags)