Skip to content

Instantly share code, notes, and snippets.

@magixx
Last active August 29, 2015 14:22
Show Gist options
  • Save magixx/daa74af630d025cf0dbe to your computer and use it in GitHub Desktop.
Save magixx/daa74af630d025cf0dbe to your computer and use it in GitHub Desktop.
def remove_from_console(console, log, levels=['DEBUG']):
to_remove = [x for x in log if x['level'] in levels]
skip_lines = 0
console_filtered = []
for index, line in enumerate(console):
if skip_lines:
skip_lines -= 1
continue
matched_logs = [x for x in to_remove if x['lines'][0] == line]
if matched_logs:
for possible_log in matched_logs:
if possible_log['lines'] == console[index:index+len(possible_log['lines'])]:
skip_lines = len(possible_log['lines'])
log.remove(possible_log)
break
if not skip_lines:
console_filtered.append(line)
return console_filtered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment