Skip to content

Instantly share code, notes, and snippets.

@bishopandco
Forked from esmarkowski/Colorized Logger
Created May 22, 2012 01:20
Show Gist options
  • Save bishopandco/2765916 to your computer and use it in GitHub Desktop.
Save bishopandco/2765916 to your computer and use it in GitHub Desktop.
beautiful colorized messages.
module ActiveSupport
class BufferedLogger
module Severity
COLORIZE = 10
end
include Severity
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
message = "\e[0;45m#{message}\e[0;0m\n" if severity == 10
# If a newline is necessary then create a new message ending with a newline.
# Ensures that the original message is not mutated.
message = "#{message}\n" unless message[-1] == ?\n
buffer << message
auto_flush
message
end
for severity in Severity.constants
class_eval <<-EOT, __FILE__, __LINE__ + 1
def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block)
end # end
def #{severity.downcase}? # def debug?
#{severity} >= @level # DEBUG >= @level
end # end
EOT
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment