Last active
August 29, 2015 14:05
-
-
Save jorrizza/33423b166c1e2a3f41b8 to your computer and use it in GitHub Desktop.
Colors standard syslog output and groups by service name
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 | |
# 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