Last active
August 29, 2015 14:12
-
-
Save tristan0x/685ad66b12d3a18b10cd to your computer and use it in GitHub Desktop.
Python logs beautifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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