Skip to content

Instantly share code, notes, and snippets.

@shanna
Created September 9, 2009 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanna/183409 to your computer and use it in GitHub Desktop.
Save shanna/183409 to your computer and use it in GitHub Desktop.
#!/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