Sha256: d29a62ccd98bf330ed6484049eed5ceeb3706480009f3589576d7f5d227b9d5b

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

module Cachetastic # :nodoc:
  # This class handles logging for the caches and their adapters.
  # This class exists simply to supply the ability to write to 
  # multiple loggers simultaneously from a single call. It also 
  # creates a standardized message to write to those loggers.
  # 
  # It is important that any logger type of class you decide to use
  # reponds to the following methods:
  #   fatal(message)
  #   error(message)
  #   warn(message)
  #   info(message)
  #   debug(message)
  class Logger
  
    # An <tt>Array</tt> of 'real' loggers to write to.
    attr_accessor :loggers
  
    # The <tt>initialize</tt> method takes an <tt>Array</tt>
    # of your favorite logger style classes to write to.
    def initialize(*loggers)
      @loggers = [loggers].flatten
    end
  
    LOG_LEVELS = [:fatal, :error, :warn, :info, :debug] # :nodoc:
  
    LOG_LEVELS.each do |level|
      define_method(level) do |*args|
        lm = "[CACHE] [#{level.to_s.upcase}]\t#{Time.now.strftime("%m/%d/%y %H:%M:%S")}"
        exs = []
        args.each do |arg|
          if arg.is_a?(Exception)
            exs << arg
            continue
          end
          lm << "\t" << arg.to_s 
        end
        exs.each do |ex|
          lm << "\n#{ex.message}\n" << ex.backtrace.join("\n")
        end
        # puts "lm: #{lm}"
        self.loggers.each do |log|
          log.send(level, lm)
        end
      end
    end
  
  end # Logger
end # Cachetastic

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
markbates-cachetastic-3.0.0.20090611142033 lib/cachetastic/logger.rb
markbates-cachetastic-3.0.1.20090625224017 lib/cachetastic/logger.rb
markbates-cachetastic-3.0.2.20090720150919 lib/cachetastic/logger.rb
markbates-cachetastic-3.0.3.20090803115537 lib/cachetastic/logger.rb
cachetastic-3.7.0 lib/cachetastic/logger.rb
cachetastic-3.6.0 lib/cachetastic/logger.rb
cachetastic-3.5.3 lib/cachetastic/logger.rb
cachetastic-3.5.2 lib/cachetastic/logger.rb
cachetastic-3.5.1 lib/cachetastic/logger.rb
cachetastic-3.5.0 lib/cachetastic/logger.rb
cachetastic-3.2.0 lib/cachetastic/logger.rb
cachetastic-3.1.0 lib/cachetastic/logger.rb
cachetastic-3.0.5.1 lib/cachetastic/logger.rb
cachetastic-3.0.5 lib/cachetastic/logger.rb
cachetastic-3.0.4 lib/cachetastic/logger.rb
cachetastic-3.0.1 lib/cachetastic/logger.rb
cachetastic-3.0.2 lib/cachetastic/logger.rb
cachetastic-3.0.3 lib/cachetastic/logger.rb
cachetastic-3.0.0 lib/cachetastic/logger.rb
cachetastic-three-3.0.0 lib/cachetastic/logger.rb