Created
September 9, 2009 02:19
-
-
Save shanna/183409 to your computer and use it in GitHub Desktop.
This file contains 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/env ruby | |
log = IO.popen("varnishlog -o") | |
loop do | |
Signal.trap('INT'){ exit 0} | |
while line = log.readline | |
next unless line =~ /^\s+\d+\s+([A-Z]\w+)\s+[-cb]\s(.*)$/ | |
head, line = $1, $2 | |
colour = case head | |
when /RxURL/ then 34 | |
when /Hit/ then 32 | |
when /ObjHeader/ then 35 | |
when /[TR]xHeader/ then 33 | |
when /Error/ then 31 | |
when /CLI/ then next # skip to the next line | |
else 0 | |
end | |
puts "\033[1;#{colour}m%-13s\033[0m %s" % [head, line] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment