3 # A base class for logging providers.
5 # Logging providers should provide the following:
7 # * start - all you need to do to setup your logging
8 # * set_logging_level - set your logging to :info, :warn, etc
9 # * valid_levels - a hash of maps from :info to your internal level name
10 # * log - what needs to be done to log a specific message
12 attr_reader :active_level
15 @known_levels = [:debug, :info, :warn, :error, :fatal]
17 # Sanity check the class that impliments the logging
18 @known_levels.each do |lvl|
19 raise "Logger class did not specify a map for #{lvl}" unless valid_levels.include?(lvl)
23 def should_log?(level)
24 @known_levels.index(level) >= @known_levels.index(@active_level)
27 # Figures out the next level and sets it
32 log(lvl, "", "Logging level is now #{lvl.to_s.upcase}")
35 # Sets a new level and record it in @active_level
37 set_logging_level(level)
38 @active_level = level.to_sym
43 raise "Logger class do not know how to handle #{level} messages" unless valid_levels.include?(level.to_sym)
45 valid_levels[level.to_sym]
48 # Gets the next level in the list, cycles down to the firt once it reaches the end
50 # if all else fails, always go to debug mode
53 if @known_levels.index(@active_level) == (@known_levels.size - 1)
54 nextlvl = @known_levels.first
56 idx = @known_levels.index(@active_level) + 1
57 nextlvl = @known_levels[idx]
63 # Abstract methods to ensure the logging implimentations supply what they should
65 raise "The logging class did not supply a valid_levels method"
68 def log(level, from, msg)
69 raise "The logging class did not supply a log method"
73 raise "The logging class did not supply a start method"