def main(): cfg = { 'host': '', 'port': 10000, 'channel': '', 'ident ': '', 'secret': '', 'tail_file': '' } if len(sys.argv) > 1: logger.info("Parsing config file: %s" % sys.argv[1]) cfg.update(json.load(file(sys.argv[1]))) for name, value in cfg.items(): if isinstance(value, basestring): # hpfeeds protocol has trouble with unicode, hence the utf-8 encoding here cfg[name] = value.encode("utf-8") else: logger.warning( "Warning: no config found, using default values for hpfeeds server" ) publisher = hpfeeds_connect(cfg['host'], cfg['port'], cfg['ident'], cfg['secret']) tail = multitail2.MultiTail(cfg['tail_file']) for filemeta, line in tail: logger.debug(filemeta, line) record = parse(line) if record: publisher.publish(cfg['channel'], json.dumps(record)) publisher.stop() return 0
def test_read(self): with tempfile.NamedTemporaryFile() as temp: mt = multitail2.MultiTail(temp.name) self.assertEqual([], list(mt.poll())) temp.write('Some data' + os.linesep) temp.flush() actual = list(mt.poll()) expected = [((temp.name, 0), 'Some data')] self.assertEqual(actual, expected)
def test_read_without_limit(self): """ When we read from a file without a specified limit, read the remainder. """ with tempfile.NamedTemporaryFile() as temp: with tempfile.NamedTemporaryFile() as temp2: mt = multitail2.MultiTail([temp.name, temp2.name]) self.assertEqual([], list(mt.poll())) temp.write('Some data' + os.linesep) temp.flush() temp2.write('Some data2' + os.linesep) temp2.flush() actual = set(mt.poll()) expected = {((temp.name, 0), 'Some data'), ((temp2.name, 0), 'Some data2')} self.assertEqual(actual, expected)
import sys sys.path.insert(0, "src") import multitail2 mt = multitail2.MultiTail(sys.argv[1], skip_to_end = False) last = None index = 0 while True: last_index = index for record in mt.poll(): last = record index += 1 if index == last_index: break print index print repr(last)
def __init__(self, base_dir, pats: List[str]): self.base_dir = base_dir self.tailer = multitail2.MultiTail( [str(base_dir / pat) for pat in pats]) self._stop_event = threading.Event() super().__init__()
import multitail2 mt = multitail2.MultiTail("./log/*.txt") for line in mt: print(line)
def __init__(self, spoolglob, progresses=None, shutdown=None): self.progresses = progresses or {} self.shutdown_e = shutdown self.data_reader = multitail2.MultiTail(spoolglob, skip_to_end=False, offsets=progresses)
def __init__(self, pats: List[str]): self.tailer = multitail2.MultiTail(pats) self._stop_event = threading.Event() super().__init__()