while True: try: frame_parser_.reset() for document in yaml.load_all(io_stream, Loader=yaml_loader_cls): yield frame_parser_.pop_frame(), document except yaml.YAMLError as e: if persistent: continue else: raise e if __name__ == '__main__': from backends import tailc from glog_parser import GlogParser, get_msg proc = tailc('/tmp/test.log') glog_parser = GlogParser() record_stream = glog_parser.process(proc.stdout) msg_stream = get_msg(record_stream) frame_stream = frame_parser(msg_stream) # frame_parser_ = FrameParser() # text_stream = frame_parser_.process(msg_stream) # io_stream = TextStreamIO(text_stream, force_readline=True) # doc_stream = yaml.safe_load_all(io_stream) # for d in doc_stream: # f = frame_parser_.pop_frame() for f, d in frame_stream: print(f) print(d)
action='append', help='filter: filter_name=args', ) args = parser.parse_args() import filters from backends import tailc, ssh_tailc log_path = args.log_path[0] # auto local / remote tailc match = re.fullmatch(r'((\w+@)?.+):(.+)', log_path) if match is None: print('reading local file:', log_path) proc = tailc(log_path) else: address, _, log_path = match.groups() print('reading SSH remote file:', log_path) proc = ssh_tailc(address, log_path) parser = GlogParser() record_stream = parser.process(proc.stdout) if args.filter: for param in args.filter: filter_name, _, filter_param = param.partition('=') func = getattr(filters, filter_name + '_filter') filter_params = [filter_param] if filter_param else [] record_stream = func(record_stream, *filter_params) msg_stream = get_msg(record_stream) for msg in msg_stream:
parser = argparse.ArgumentParser( description="glog filter", formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) parser.add_argument( 'log_path', nargs=1, help='path to log file', ) parser.add_argument( '--filter', '-f', action='append', help='filter: filter_name=args', ) args = parser.parse_args() import filters from backends import tailc proc = tailc(args.log_path[0]) parser = GlogParser() record_stream = parser.process(proc.stdout) if args.filter: for param in args.filter: filter_name, _, filter_param = param.partition('=') func = getattr(filters, filter_name + '_filter') filter_params = [filter_param] if filter_param else [] record_stream = func(record_stream, *filter_params) msg_stream = get_msg(record_stream) for msg in msg_stream: print(msg)
""" Created on Fri Sep 20 10:42:02 2019 @author: Macrobull """ from __future__ import absolute_import, division, unicode_literals # import ysl. from backends import tailc from filters import thread_filter from glog_parser import GlogParser, get_msg from parsers import FrameParser, frame_parser # setup source proc = tailc('/tmp/demo.log') glog_parser = GlogParser() record_stream = glog_parser.process(proc.stdout) # select one thread to parse thread_id = None while True: if thread_id is None: for record in record_stream: match = FrameParser.REGEX.fullmatch(record.msg) if match: frame = FrameParser.make_frame(*match.groups()) if frame.name.startswith('Thread'): thread_id = record.thread_id break else: