lib/ramaze/log/rotatinginformer.rb in manveru-ramaze-2009.04.22 vs lib/ramaze/log/rotatinginformer.rb in manveru-ramaze-2009.05

- old
+ new

@@ -1,18 +1,18 @@ module Ramaze - + module Logger # A customized logger (based on Informer) that creates multiple log files based on time class RotatingInformer - + include Innate::Traited include Logging attr_accessor :time_format, :log_levels attr_reader :base_dir - + # parameter for Time.now.strftime trait :timestamp => "%Y-%m-%d %H:%M:%S" # This is how the final output is arranged. trait :format => "[%time] %prefix %text" @@ -45,28 +45,28 @@ # logged to the files. def initialize(base_dir, time_format = '%Y-%m-%d.log', log_levels = [:debug, :error, :info, :warn]) # Verify and set base directory send :base_dir=, base_dir, true - + @time_format = time_format @log_levels = log_levels - + # Keep track of log shutdown (to prevent StackErrors due to recursion) @in_shutdown = false end # Set the base directory for log files - # + # # If this method is called with the raise_exception # parameter set to true the method will raise an exception # if the specified directory does not exist or is unwritable. - # + # # If raise_exception is set to false, the method will just # silently fail if the specified directory does not exist # or is unwritable - + def base_dir=(directory, raise_exception = false) # Expand directory path base_dir = File.expand_path(directory) # Verify that directory path exists if File.exist?(base_dir) @@ -83,11 +83,11 @@ end else raise Exception.new("#{base_dir} does not exist.") if raise_exception end end - + # Close the file we log to if it isn't closed already. def shutdown if @out.respond_to?(:close) unless @in_shutdown @@ -104,10 +104,10 @@ def log tag, *messages return unless @log_levels.include?(tag) # Update current log - update_current_log + update_current_log messages.flatten! prefix = tag.to_s.upcase.ljust(5)