Class: Fog::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/core/logger.rb

Class Method Summary collapse

Class Method Details

.[](channel) ⇒ Object



9
10
11
# File 'lib/rackspace-fog/core/logger.rb', line 9

def self.[](channel)
  @channels[channel]
end

.[]=(channel, value) ⇒ Object



13
14
15
# File 'lib/rackspace-fog/core/logger.rb', line 13

def self.[]=(channel, value)
  @channels[channel] = value
end

.debug(message) ⇒ Object



17
18
19
# File 'lib/rackspace-fog/core/logger.rb', line 17

def self.debug(message)
  self.write(:debug, "[light_black][DEBUG] #{message}[/]\n")
end

.deprecation(message) ⇒ Object



21
22
23
# File 'lib/rackspace-fog/core/logger.rb', line 21

def self.deprecation(message)
  self.write(:deprecation, "[yellow][DEPRECATION] #{message}[/]\n")
end

.warning(message) ⇒ Object



25
26
27
# File 'lib/rackspace-fog/core/logger.rb', line 25

def self.warning(message)
  self.write(:warning, "[yellow][WARNING] #{message}[/]\n")
end

.write(key, value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rackspace-fog/core/logger.rb', line 29

def self.write(key, value)
  if channel = @channels[key]
    value.gsub(Formatador::INDENT_REGEX, '')
    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