2011-09-01 18:48:43 -04:00
|
|
|
module Fog
|
|
|
|
class Logger
|
|
|
|
|
|
|
|
@channels = {
|
2011-10-19 15:49:34 -04:00
|
|
|
:deprecation => ::STDOUT,
|
|
|
|
:warning => ::STDOUT
|
2011-09-01 18:48:43 -04:00
|
|
|
}
|
2013-10-21 12:33:43 -04:00
|
|
|
|
2013-01-14 11:20:29 -05:00
|
|
|
@channels[:debug] = ::STDOUT if ENV['DEBUG']
|
2011-09-01 18:48:43 -04:00
|
|
|
|
2011-09-01 19:51:08 -04:00
|
|
|
def self.[](channel)
|
|
|
|
@channels[channel]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.[]=(channel, value)
|
|
|
|
@channels[channel] = value
|
|
|
|
end
|
|
|
|
|
2011-09-01 18:48:43 -04:00
|
|
|
def self.debug(message)
|
2013-10-21 12:33:43 -04:00
|
|
|
self.write(:debug, "[light_black][fog][DEBUG] #{message}[/]\n")
|
2011-09-01 18:48:43 -04:00
|
|
|
end
|
|
|
|
|
2011-10-19 15:49:34 -04:00
|
|
|
def self.deprecation(message)
|
2013-10-21 12:33:43 -04:00
|
|
|
self.write(:deprecation, "[yellow][fog][DEPRECATION] #{message}[/]\n")
|
2011-10-19 15:49:34 -04:00
|
|
|
end
|
|
|
|
|
2011-09-01 18:48:43 -04:00
|
|
|
def self.warning(message)
|
2013-10-21 12:33:43 -04:00
|
|
|
self.write(:warning, "[yellow][fog][WARNING] #{message}[/]\n")
|
2011-09-01 18:48:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.write(key, value)
|
|
|
|
if channel = @channels[key]
|
|
|
|
message = if channel.tty?
|
|
|
|
value.gsub(Formatador::PARSE_REGEX) { "\e[#{Formatador::STYLES[$1.to_sym]}m" }.gsub(Formatador::INDENT_REGEX, '')
|
|
|
|
else
|
|
|
|
value.gsub(Formatador::PARSE_REGEX, '').gsub(Formatador::INDENT_REGEX, '')
|
|
|
|
end
|
|
|
|
channel.write(message)
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|