Skip to content

Instantly share code, notes, and snippets.

@timuruski
Created December 23, 2013 23:46
Show Gist options
  • Save timuruski/8106740 to your computer and use it in GitHub Desktop.
Save timuruski/8106740 to your computer and use it in GitHub Desktop.
Operates a bit like sed without having to rebuild a string from an array of lines.
LOG_PATTERN = /^(INFO|DEBUG)\t[-0-9]+ [:0-9]+\t/
def filter_and_format(log, level)
log.each_line.with_object("") { |line, filtered|
next unless line.start_with?(level)
filtered << line.sub(LOG_PATTERN, '')
}
end
@timuruski
Copy link
Author

Somewhat equivalent to:

sed -E "/^DEBUG/d; s/^(INFO|DEBUG) [-0-9]+ [:0-9]+ //"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment