Created
June 14, 2016 07:53
-
-
Save rainchen/ed170d57dfaa6d1f2585642b59e1f923 to your computer and use it in GitHub Desktop.
Revisions
-
rainchen created this gist
Jun 14, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ 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