lib/cachetastic/logger.rb in cachetastic-2.1.4 vs lib/cachetastic/logger.rb in cachetastic-3.0.0
- old
+ new
@@ -1,49 +1,49 @@
-# This class handles logging for the caches and their adapters.
-class Cachetastic::Logger
+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
- # attr_accessor :options
- # attr_accessor :cache_name
- attr_accessor :loggers
+ # An <tt>Array</tt> of 'real' loggers to write to.
+ attr_accessor :loggers
- def initialize(loggers)
- @loggers = [loggers].flatten
- # self.options = options
- # self.cache_name = cache_name
- # self.options.each_pair do |n, opts|
- # opts["level"] = (opts["level"] ||= "info").to_sym
- # end
- end
+ # 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]
+ 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
+ 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
- lm << "\t" << arg.to_s
+ 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
- exs.each do |ex|
- lm << "\n#{ex.message}\n" << ex.backtrace.join("\n")
- end
- self.loggers.each do |log|
- log.send(level, lm)
- end
- # self.options.each_pair do |n, opts|
- # if LOG_LEVELS.index(opts["level"]) >= LOG_LEVELS.index(level)
- # case opts["type"]
- # when "file"
- # File.open(opts["file"], "a") {|f| f.puts(lm)}
- # when "console"
- # puts lm
- # end
- # end
- # end
end
- end
-end
+ end # Logger
+end # Cachetastic
\ No newline at end of file