Sha256: c6021ca553552ea7bc90d77509f1b487f920d1214f33419a53ef7c3ae623caf1

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 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}\n"
        end
      else
        @messages << message
      end
    end

    def self.info(message)
      if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
        Rails.logger.info(message)
      elsif @logfile
        File.open(@logfile, "a") do |f|
          f << "#{message}\n"
        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}\n"
        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}\n"
        end
      else
        @messages << message
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_rest_client-1.2.0 lib/active_rest_client/logger.rb
active_rest_client-1.1.12 lib/active_rest_client/logger.rb
active_rest_client-1.1.11 lib/active_rest_client/logger.rb
active_rest_client-1.1.10 lib/active_rest_client/logger.rb
active_rest_client-1.1.9 lib/active_rest_client/logger.rb
active_rest_client-1.1.0 lib/active_rest_client/logger.rb
active_rest_client-1.0.9 lib/active_rest_client/logger.rb
active_rest_client-1.0.8 lib/active_rest_client/logger.rb