def _main(filepath, options): try: if options.lines > 0: with open(filepath, 'rb') as f: if options.head: if options.follow: sys.stderr.write('Cannot follow from top of file.\n') sys.exit(1) lines = head(f, options.lines) else: lines = tail(f, options.lines) encoding = locale.getpreferredencoding() for line in lines: print(line.decode(encoding)) if options.follow: for line in follow_path(filepath): if line is not None: print(line) else: time.sleep(options.sleep) except KeyboardInterrupt: # Escape silently pass
def main(): # setup logging loglevel = logging.INFO console = logging.StreamHandler() logging.getLogger('').setLevel(loglevel) console.setFormatter(logging.Formatter(LOG_FORMAT)) logging.getLogger('').addHandler(console) events = [] for line in tailer.follow_path(filename): if line is not None: events.append(line) else: if events: sent_count = process_events(events) logger.info("sent {0} ufw events to whiteface".format(sent_count)) time.sleep(sleep_seconds) logger.info("looking for new ufw events") events = []