Skip to content

Instantly share code, notes, and snippets.

@flockonus
Created November 1, 2010 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flockonus/659039 to your computer and use it in GitHub Desktop.
Save flockonus/659039 to your computer and use it in GitHub Desktop.
/lib/action_logger.rb
class ActionLogger
@@queue = []
@@limit = (Rails.env == 'development' ? 0 : 100 )
def self.add(str)
@@queue.push(str)
store! if @@queue.size >= @@limit
end
def self.store!
f = File.new("log/actions#{Date.today.to_s}.log", 'a')
flush().each do |act|
f.puts(act)
end
f.close
end
protected
def self.flush()
a = @@queue
@@queue = []
return a
end
end
at_exit do
ActionLogger.store!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment