Skip to content

Instantly share code, notes, and snippets.

@chadmoone
Last active December 16, 2015 08:49
Show Gist options
  • Save chadmoone/5408657 to your computer and use it in GitHub Desktop.
Save chadmoone/5408657 to your computer and use it in GitHub Desktop.
ActiveSupport Concern to enable logging in technicolor.
module Tracer extend ActiveSupport::Concern
included do
unless (const_defined?(:TRACER_INIT))
# Prevent redefining constants when Rails reloads
TRACER_INIT = true;
# Formatting Options
CLEAR = "\e[0m"
BOLD = "\e[1m"
UNDERSCORE = "\e[4m"
BLINK = "\e[5m"
REVERSE = "\e[7m"
CONCEALED = "\e[8m"
# Foreground Colors
BLACK = "\e[30m"
RED = "\e[31m"
GREEN = "\e[32m"
YELLOW = "\e[33m"
BLUE = "\e[34m"
MAGENTA = "\e[35m"
CYAN = "\e[36m"
WHITE = "\e[37m"
# Background Colors
BLACK_BG = "\e[40m"
RED_BG = "\e[41m"
GREEN_BG = "\e[42m"
YELLOW_BG = "\e[43m"
BLUE_BG = "\e[44m"
MAGENTA_BG = "\e[45m"
CYAN_BG = "\e[46m"
WHITE_BG = "\e[47m"
end
def send_log(s, color=nil, bg_color=nil, formatting=nil)
logger.debug "#{formatting unless formatting.nil?}#{color unless color.nil?}#{bg_color unless bg_color.nil?}#{s}#{CLEAR}"
# logger.debug "#{BOLD}#{BLINK}#{YELLOW_BG}#{MAGENTA}#{s}#{CLEAR}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment