Beispiel #1
0
def main():
    prs = argparse.ArgumentParser()
    prs.add_argument('-f', '--filter', nargs='*',
                     help="Add a filter in for of 'APP:CTX'")
    prs.add_argument('-t', '--transform', nargs='*',
                     help="Use a transform module")
    prs.add_argument('--raw', action='store_true',
                     help="Don't expect storage headers. "
                          "Useful for things like 'socat tcp:host:port stdout | dltpy-print --raw'")
    prs.add_argument('file', nargs=1)
    cli_common.setup_logs()
    args = prs.parse_args()
    fn = args.file[0]
    filters = cli_common.parse_filters(args.filter)
    transforms = cli_common.load_transforms(args.transform)

    logging.warning("Will print file %s with filters: %s", fn, filters)
    with open(fn, 'rb') as fd:
        dltf = dltfile.DltReader(fd.readinto, filters, expect_storage_header=not args.raw)
        dltf = apply_transforms(dltf, transforms)
        for dm in dltf:
            try:
                print(cli_common.message_str(dm))
            except Exception as ex:
                logging.exception("Failed to parse")
                print("ERROR: %s" % ex)
Beispiel #2
0
def main():
    prs = argparse.ArgumentParser()
    prs.add_argument('-f',
                     '--filter',
                     help="Messages to pick, 'APP:CTX'",
                     nargs='*')
    prs.add_argument('-s', '--lifecycle-split', action='store_true')
    prs.add_argument('--lifecycle-threshold', type=float, default=30)
    prs.add_argument('-o', '--output')
    prs.add_argument('files', help='files to process', nargs='*')
    cli_common.setup_logs()
    args = prs.parse_args()
    filters = cli_common.parse_filters(args.filter)

    current_ts = 0
    ts_threshold = args.lifecycle_threshold
    out_fn_counter = 0
    out_fn_base = Path(args.output)
    out_fd = None

    if args.lifecycle_split:
        logging.warning("LC split with threshold %.1f sec", ts_threshold)

    for fn in args.files:
        logging.info("Processing %s", fn)
        with open(fn, 'rb') as f:
            dlt = df.DltReader(f.readinto, filters)
            for msg in dlt:
                assert isinstance(msg, df.DltMessage)
                if (msg.ts - current_ts < -ts_threshold
                        and args.lifecycle_split) or out_fd is None:
                    if not out_fd is None:
                        out_fd.close()

                    out_fn = out_fn_base
                    if args.lifecycle_split:
                        out_fn = out_fn_base.parent / (
                            '%s%02d%s' % (out_fn_base.stem, out_fn_counter,
                                          out_fn_base.suffix))
                        out_fn_counter += 1

                    out_fd = out_fn.open('wb')
                current_ts = msg.ts
                out_fd.write(msg._raw_message)

    if out_fd is None:
        logging.warning("No records written!")
    else:
        out_fd.close()
Beispiel #3
0
def main():
    prs = argparse.ArgumentParser()
    prs.add_argument('--host', default='localhost')
    prs.add_argument('--filter',
                     '-f',
                     help="Filter logs, 'APP:CTX'",
                     nargs='*')
    prs.add_argument('output', help="Save the log to a .dlt file")

    cli_common.setup_logs()

    args = prs.parse_args()

    host = args.host
    port = 3490

    flt = cli_common.parse_filters(args.filter)
    out_fn = args.output
    if ':' in host:
        host, port = host.split(':')
        port = int(port)

    ar = AsyncReceiver((host, port), out_fn, flt)
    asyncio.get_event_loop().run_until_complete(ar.run())