Skip to content

Instantly share code, notes, and snippets.

@ryanneufeld
Last active December 10, 2015 14:29
Show Gist options
  • Save ryanneufeld/4448251 to your computer and use it in GitHub Desktop.
Save ryanneufeld/4448251 to your computer and use it in GitHub Desktop.
Colorize CodeIgniter logs. ``` $ ci_color_log_tail /path/to/application/logs/log-2013-01-03.php $ ci_color_log_tail /path/to/application/logs/log-2013-01-03.php 300 #start with 300 lines of log. ```
# This version colors only the keyword at the beginning of the line
ci_color_log_tail() {
tail -f -n ${2:-100} $1 | awk '{if ($1 == "DEBUG") { c=34 } else if ($1 == "WARNING") { c=32 } else if ($1 == "ERROR") { c=31 } else { c=39 }; printf "\033[1;" c "m%s\033[0m ", $1; for (i = 2; i <= NF; i++) printf $i " "; printf "\n"}'
}
# This version colors the entire line.
ci_color_log_tail() {
tail -f -n ${2:-100} $1 | awk '{if ($1 == "DEBUG") { c=34 } else if ($1 == "WARNING") { c=32 } else if ($1 == "ERROR") { c=31 } else { c=39 }; printf "\033[1;" c "m%s\033[0m\n", $0;}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment