Sha256: bc6ab75e74999236d04953b5f2a58da07fd3a3b8b23a70019f78463093f9952a

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Fog
  class Logger
    @channels = {
      :deprecation  => ::STDERR,
      :warning      => ::STDERR
    }

    @channels[:debug] = ::STDERR if ENV["DEBUG"]

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

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

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-core-1.27.3 lib/fog/core/logger.rb