activerecord - In the rails 4 console, how do I log all sql activity to file BUT not to the console output? -
lots of similar questions ask how hide sql logs in console window, , answers suggest changing log level of active record or turning off ar logging altogether.
however still want ar log everything, wanted log file only, , not console output window (as makes console noisy can't see manual logs).
how achieve want?
this activerecord::railtie code says broadcast logger messages console:
# when loading console, force activerecord::base loaded # avoid cross references when loading constant # first time. also, make output stderr. console |app| require "active_record/railties/console_sandbox" if app.sandbox? require "active_record/base" console = activesupport::logger.new(stderr) rails.logger.extend activesupport::logger.broadcast console end
so 1 thing when first console set activerecord::base.logger
new logger not broadcast messages console. example:
activerecord::base.logger = activesupport::logger.new("log/development.log")
"log/development.log" can changed wherever want send sql output.
Comments
Post a Comment