Sha256: 2602fd399664595504ac1e1e8be3f08c896a4ee8a4124869070d0997c7e75f0a

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 KB

Contents

module ActiveRestClient
  class Logger
    @logfile = nil
    @messages = []

    def self.logfile=(value)
      @logfile = value
    end

    def self.messages
      @messages
    end

    def self.reset!
      @logfile = nil
      @messages = []
    end

    def self.debug(message)
      if defined?(Rails) && Rails.respond_to?(:logger)
        Rails.logger.debug(message)
      elsif @logfile
        File.open(@logfile, "a") do |f|
          f << message
        end
      else
        @messages << message
      end
    end

    def self.info(message)
      if defined?(Rails) && Rails.respond_to?(:logger)
        Rails.logger.info(message)
      elsif @logfile
        File.open(@logfile, "a") do |f|
          f << message
        end
      else
        @messages << message
      end
    end

    def self.warn(message)
      if defined?(Rails) && Rails.respond_to?(:logger)
        Rails.logger.warn(message)
      elsif @logfile
        File.open(@logfile, "a") do |f|
          f << message
        end
      else
        @messages << message
      end
    end

    def self.error(message)
      if defined?(Rails) && Rails.respond_to?(:logger)
        Rails.logger.error(message)
      elsif @logfile
        File.open(@logfile, "a") do |f|
          f << message
        end
      else
        @messages << message
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_rest_client-1.0.3 lib/active_rest_client/logger.rb
active_rest_client-1.0.2 lib/active_rest_client/logger.rb
active_rest_client-1.0.1 lib/active_rest_client/logger.rb
active_rest_client-1.0.0 lib/active_rest_client/logger.rb
active_rest_client-0.9.75 lib/active_rest_client/logger.rb
active_rest_client-0.9.73 lib/active_rest_client/logger.rb
active_rest_client-0.9.72 lib/active_rest_client/logger.rb
active_rest_client-0.9.71 lib/active_rest_client/logger.rb
active_rest_client-0.9.70 lib/active_rest_client/logger.rb
active_rest_client-0.9.69 lib/active_rest_client/logger.rb
active_rest_client-0.9.68 lib/active_rest_client/logger.rb
active_rest_client-0.9.67 lib/active_rest_client/logger.rb
active_rest_client-0.9.66 lib/active_rest_client/logger.rb
active_rest_client-0.9.65 lib/active_rest_client/logger.rb
active_rest_client-0.9.60 lib/active_rest_client/logger.rb
active_rest_client-0.9.59 lib/active_rest_client/logger.rb
active_rest_client-0.9.58 lib/active_rest_client/logger.rb