📜 ⬆️ ⬇️

Enabling log output in script / console

I often miss the output of the SQL log when I call the find method of the ActiveRecord model in the console. If you add the following lines to the ~ / .irbrc file, the log will be output directly to the console:

 script_console_running = ENV.include? ('RAILS_ENV') && IRB.conf [: LOAD_MODULES] && IRB.conf [: LOAD_MODULES] .include? ('console_with_helpers')
 rails_running = ENV.include? ('RAILS_ENV') &&! (IRB.conf [: LOAD_MODULES] && IRB.conf [: LOAD_MODULES] .include? ('console_with_helpers'))
 irb_standalone_running =! script_console_running &&! rails_running

 if script_console_running
   require 'logger'
   Object.const_set (: RAILS_DEFAULT_LOGGER, Logger.new (STDOUT))
 end

')

Source: https://habr.com/ru/post/84010/


All Articles