#!/usr/bin/env ruby if __FILE__ == $0 colors = (32..37).map {|c| "\e[#{c}m" } STDIN.each_line do |l| if l =~ /\A(\d+)?\s+([0-9:]+)?\s+(\d+) (\w+) (.+)\Z/ time, time2, id, command, argument = $1, $2, $3.to_i, $4.to_s.strip, $5.to_s.strip tx_demarc = command == 'Query' && ['begin', 'commit', 'rollback', 'set autocommit=1'].include?(argument.downcase) bg = tx_demarc ? "\e[41m" : "\e[49m" puts "-" * 120 if command == 'Connect' printf "%s%s%s\e[0m", colors[id % colors.size], bg, l end end end