Guest User

Untitled

a guest
Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class ActionLogger
  2. @@queue = []
  3. @@limit = (Rails.env == 'development' ? 0 : 100 )
  4.  
  5. def self.add(str)
  6. @@queue.push(str)
  7. store! if @@queue.size >= @@limit
  8. end
  9.  
  10. def self.store!
  11. f = File.new("log/actions#{Date.today.to_s}.log", 'a')
  12. flush().each do |act|
  13. f.puts(act)
  14. end
  15. f.close
  16. end
  17.  
  18. protected
  19.  
  20. def self.flush()
  21. a = @@queue
  22. @@queue = []
  23. return a
  24. end
  25. end
  26.  
  27. at_exit do
  28. ActionLogger.store!
  29. end
Add Comment
Please, Sign In to add comment