Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. # an application initializer which configures a rails application for logging
  2. #
  3. module RailsApp
  4. class Application < Rails::Application
  5. # load the libs - don't forget lockfile for process safe log rolling
  6. #
  7. require 'logging' unless defined?(Logging)
  8. require 'lockfile' unless defined?(Lockfile)
  9.  
  10. # do the actual logging configuration - this one will keep 7 log files of
  11. # roughly 42 mega-bytes on disk and fill not your lovely drive - unless you
  12. # are in IRB, in which case the logger is not touched...
  13. #
  14. # it *seems* like this should be in an initializer but, alas, rails does
  15. # some weird things with dup'ing loggers that makes it safer to do right
  16. # *here*
  17. #
  18. unless STDIN.tty?
  19. require 'fileutils'
  20. FileUtils.mkdir_p(File.join(Rails.root, 'log'))
  21.  
  22. logpath = config.paths.log.first.to_s
  23. number_rolled = 7
  24. megabytes = 2 ** 20
  25. max_size = 42 * megabytes
  26. options = { :safe => true } # for multi-process safe rolling with lockfile
  27.  
  28. logger = ::Logging.logger(logpath, number_rolled, max_size, options)
  29.  
  30. config.logger = logger
  31. config.logger.level = Rails.env.production? ? :info : :debug
  32. end
  33. end
  34. end
  35.  
  36. ### you can test this using something like this
  37. #
  38. # rails runner 'p ActiveRecord::Base.logger; ActiveRecord::Base.logger.info("foobar"); ' < /dev/null
  39. # cat log/development.log
Add Comment
Please, Sign In to add comment