Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

1.6 Logging requests (due to REST hits, DB hits, filesystem hits and so on), Ruby will now have the option of scheduling another request to execute. Put another way, removing the coarse-grained lock will at least improve concurrency up to the "best" that green-threaded implementations can do, which isn't too bad. 23 Config To learn the practical implications of writing thread-safe application code, the extent of which exceed the scope of this book, make sure to study Pratik Naik's excellent (but foul-mouthed) analysis of the subject. 10 1.6 Logging Most programming contexts in Rails (models, controllers, view templates) have a logger attribute, which holds a reference to a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class. Can't get a reference to logger somewhere in your code? The Rails.logger method references a logger that you can use anywhere. It's really easy to create a new Logger in Ruby, as shown in the following example: $ irb > require 'logger' => true irb(main):002:0> logger = Logger.new STDOUT => #<Logger:0x32db4c @level=0, @progname=nil, @logdev= #<Logger::LogDevice:0x32d9bc ... > > logger.warn "do not want!!!" W, [2007-06-06T17:25:35.666927 #7303] => true WARN -- : do not want!!! > logger.info "in your logger, giving info" I, [2007-06-06T17:25:50.787598 #7303] INFO -- : in your logger, giving your info => true Typically, you add a message to the log using the logger whenever the need arises, using a method corresponding to the severity of the log message. The standard logger's severities are (in increasingly severe order): debug Use the debug level to capture data and application state useful for debugging problems later on. This level is not usually captured in production logs. 10. http://m.onkey.org/2008/10/23/thread-safety-for-your-rails