Skip to content

Instantly share code, notes, and snippets.

@jorrizza
Last active August 29, 2015 14:05
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 jorrizza/33423b166c1e2a3f41b8 to your computer and use it in GitHub Desktop.
Save jorrizza/33423b166c1e2a3f41b8 to your computer and use it in GitHub Desktop.
Colors standard syslog output and groups by service name
#!/usr/bin/env ruby
# Colors standard syslog output and groups by service name
require 'time'
services = []
STDIN.each_line do |line|
match = line.strip.match(/\A(?<timestamp>[\w]{3} \d+ \d\d:\d\d:\d\d) (?<hostname>[\w\d\-]+) (?<service>.+?): (?<message>.+)\z/)
if match
timestamp = Time.parse(match[:timestamp]).strftime('%y-%m-%d %H:%M:%S')
hostname = match[:hostname]
service = match[:service].gsub(/\[\d+\]/, '') # Remove optional PID suffix
message = match[:message]
services << service unless services.include?(service)
color = services.index(service) % 6 + 31 # One of the primary terminal colors
puts "\033[#{color}m#{timestamp} \033[1m#{hostname}\033[22m #{service}\033[39m #{message}"
else
puts line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment