Created
August 9, 2012 21:43
-
-
Save schubert/3308296 to your computer and use it in GitHub Desktop.
colorize your chef solo output (put in libraries)
This file contains hidden or 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
require "mixlib/log/formatter" | |
module Mixlib | |
module Log | |
class Formatter < Logger::Formatter | |
# Prints a log message as '[time] severity: message' if Chef::Log::Formatter.show_time == true. | |
# Otherwise, doesn't print the time. | |
def call(severity, time, progname, msg) | |
if @@show_time | |
reset = "\033[0m" | |
color = case severity | |
when "FATAL" | |
"\033[1;41m" # Bright Red | |
when "ERROR" | |
"\033[31m" # Red | |
when "WARN" | |
"\033[33m" # Yellow | |
when "DEBUG" | |
"\033[2;37m" # Faint Gray | |
else | |
reset # Normal | |
end | |
sprintf("[%s] #{color}%s#{reset}: %s\n", time.iso8601(), severity, msg2str(msg)) | |
else | |
sprintf("%s: %s\n", severity, msg2str(msg)) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment