class Statistic # save message to a log file # usage: # Statistic.log "message" # Statistic.log { var } def self.log(message = nil, &block) @logger ||= Logger.new(Rails.root.join('log', "statistic.#{Rails.env}.log")) begin message = yield if block_given? @logger.info("#{Time.current} #{message}") rescue Exception => e # make sure the log method will not be stop the main progress @logger.info("#{Time.current} error:#{e} for #{block}") end end end