Skip to content

Instantly share code, notes, and snippets.

@tristan0x
Last active August 29, 2015 14:12
Show Gist options
  • Save tristan0x/685ad66b12d3a18b10cd to your computer and use it in GitHub Desktop.
Save tristan0x/685ad66b12d3a18b10cd to your computer and use it in GitHub Desktop.
Python logs beautifier
#!/usr/bin/awk -f
# Python logs beautifier
# Handled multi-line errors when each line starts with the ↪
# Example of usage:
# tail -f celery.log | hip-py-log
BEGIN {
# color code of the previous line
prev_code = 0
}
function color_line(code, line) {
print "\033[" code "m" line "\033[0m" ;
prev_code = code
}
# green
/INFO/ { color_line("32", $0) ; next}
# bold yellow
/WARNING|\[warn\]/ { color_line("1;33", $0) ; next }
# red
/ERROR|CRITICAL|\[error\]|\[crit\]/ { color_line("31", $0) ; next }
# Handle Docido custom multi-line log formatter
# Multi-line are colored like the previous one
/^↪/ { color_line(prev_code, $0) ; next}
# print lines that don't match any of the rule above
{ print }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment