lib/imw/utils/log.rb in imw-0.2.1 vs lib/imw/utils/log.rb in imw-0.2.2

- old
+ new

@@ -2,36 +2,60 @@ module IMW # Default log file. LOG_FILE_DESTINATION = STDERR unless defined?(LOG_FILE_DESTINATION) - - LOG_TIMEFORMAT = "%Y%m%d-%H:%M:%S " unless defined?(LOG_TIMEFORMAT) - class << self; attr_accessor :log end + # Default log file time format + LOG_TIMEFORMAT = "%Y-%m-%d %H:%M:%S " unless defined?(LOG_TIMEFORMAT) + + # Default verbosity + VERBOSE = false + + class << self; attr_accessor :log, :verbose end + + # Is IMW operating in verbose mode? + # + # Calls to <tt>IMW.warn_if_verbose</tt> and friends utilize this + # method. Verbosity is controlled on the command line (see + # IMW::Runner) or by setting IMW::VERBOSE in your configuration + # file. + # + # @return [nil, false, true] + def self.verbose? + VERBOSE || verbose + end # Create a Logger and point it at IMW::LOG_FILE_DESTINATION which is # set in ~/.imwrc and defaults to STDERR. def self.instantiate_logger! IMW.log ||= Logger.new(LOG_FILE_DESTINATION) IMW.log.datetime_format = "%Y%m%d-%H:%M:%S " IMW.log.level = Logger::INFO end - def announce *events + def self.announce *events options = events.flatten.extract_options! options.reverse_merge! :level => Logger::INFO IMW.log.add options[:level], events.join("\n") end - def banner *events + def self.announce_if_verbose *events + announce(*events) if IMW.verbose? + end + + def self.banner *events options = events.flatten.extract_options! options.reverse_merge! :level => Logger::INFO announce(["*"*75, events, "*"*75], options) end - def warn *events + + def self.warn *events options = events.flatten.extract_options! options.reverse_merge! :level => Logger::WARN announce events, options + end + def self.warn_if_verbose *events + warn(*events) if IMW.verbose? end PROGRESS_TRACKERS = {} # # When the slowly-changing tracked variable +var+ changes value,