def main(log_file, drop_event, drop_logger, replacements, replacements_from_file, output): if replacements_from_file: replacements = replacements_from_file.read() if not replacements: replacements = '{}' try: replacements = json.loads(replacements) except (JSONDecodeError, UnicodeDecodeError) as ex: raise UsageError(f'Option "--replacements" contains invalid JSON: {ex}') from ex log_records, known_fields = parse_log(log_file) prog_bar = click.progressbar(log_records, label='Rendering', file=_default_text_stderr()) with prog_bar as log_records_progr: print( render( log_file.name, transform_records( filter_records( log_records_progr, drop_events=set(d.lower() for d in drop_event), drop_loggers=set(l.lower() for l in drop_logger), ), replacements, ), len(log_records), known_fields, ), file=output, )
def main(log_file, drop_event, drop_logger, replacements, replacements_from_file, output): if replacements_from_file: replacements = replacements_from_file.read() if not replacements: replacements = '{}' try: replacements = json.loads(replacements) except (JSONDecodeError, UnicodeDecodeError) as ex: raise UsageError( f'Option "--replacements" contains invalid JSON: {ex}') from ex log_records, known_fields = parse_log(log_file) prog_bar = click.progressbar(log_records, label='Rendering', file=_default_text_stderr()) with prog_bar as log_records_progr: print( render( log_file.name, transform_records( filter_records( log_records_progr, drop_events=set(d.lower() for d in drop_event), drop_loggers=set(l.lower() for l in drop_logger), ), replacements, ), len(log_records), known_fields, ), file=output, )
def main( log_file, drop_event, drop_logger, replacements, replacements_from_file, time_range, output, ): if replacements_from_file: replacements = replacements_from_file.read() if not replacements: replacements = '{}' try: replacements = json.loads(replacements) except (JSONDecodeError, UnicodeDecodeError) as ex: raise UsageError( f'Option "--replacements" contains invalid JSON: {ex}') from ex time_from, _, time_to = time_range.partition('^') time_range = ( datetime.fromisoformat(time_from) if time_from else TIME_PAST, datetime.fromisoformat(time_to) if time_to else TIME_FUTURE, ) click.echo('Parsing log...') log_records, known_fields = parse_log(log_file) prog_bar = click.progressbar(log_records, label='Rendering', file=_default_text_stderr()) with prog_bar as log_records_progr: print( render( log_file.name, transform_records( filter_records( log_records_progr, drop_events=set(d.lower() for d in drop_event), drop_loggers=set(l.lower() for l in drop_logger), time_range=time_range, ), replacements, ), len(log_records), known_fields, ), file=output, )
def main(log_file, drop_event, drop_logger, output): log_records, known_fields = parse_log(log_file) prog_bar = click.progressbar(log_records, label='Rendering', file=_default_text_stderr()) with prog_bar as log_records_progr: print( render( log_file.name, filter_records( log_records_progr, drop_events=set(d.lower() for d in drop_event), drop_loggers=set(l.lower() for l in drop_logger), ), len(log_records), known_fields, ), file=output, )
def main( log_file: TextIO, drop_events: List[str], keep_events: List[str], drop_loggers: List[str], replacements: str, replacements_from_file: TextIO, time_range: str, wrap: bool, time_diff: bool, highlight_records: List[int], output: TextIO, ) -> None: if replacements_from_file: replacements = replacements_from_file.read() if not replacements: replacements = "{}" try: replacements_dict = json.loads(replacements) except (JSONDecodeError, UnicodeDecodeError) as ex: raise UsageError( f"Option '--replacements' contains invalid JSON: {ex}") from ex if drop_events and keep_events: raise UsageError( f"Options '--keep-event' and '--drop-event' cannot be used together." ) time_from, _, time_to = time_range.partition("^") time_range_dt = ( datetime.fromisoformat(time_from) if time_from else TIME_PAST, datetime.fromisoformat(time_to) if time_to else TIME_FUTURE, ) click.secho(f"Processing {click.style(log_file.name, fg='yellow')}", fg="green") log_records, known_fields = parse_log(log_file) prog_bar = click.progressbar(log_records, label=click.style("Rendering", fg="green"), file=_default_text_stderr()) with prog_bar as log_records_progr: render( log_file.name, transform_records( filter_records( log_records_progr, drop_events=set(d.lower() for d in drop_events), keep_events=set(k.lower() for k in keep_events), drop_loggers=set(l.lower() for l in drop_loggers), time_range=time_range_dt, ), replacements=replacements_dict, ), known_fields=known_fields, output=output, wrap=wrap, show_time_diff=time_diff, highlight_records=highlight_records, ) click.secho(f"Output written to {click.style(output.name, fg='yellow')}", fg="green")