Disable Rails SQL logging in console
To turn it off:
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
To turn it back on:
ActiveRecord::Base.logger = old_logger
How do I turn on SQL debug logging for ActiveRecord in RSpec tests?
By default, all your db queries will be logged already in test mode. They'll be in log/test.log
.
How can I disable logging of asset pipeline (sprockets) messages in Ruby on Rails 3.1?
Place the following code in config/initializers/quiet_assets.rb
if Rails.env.development?
Rails.application.assets.try(:logger=, Logger.new('/dev/null'))
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
Rails.logger.level = previous_level
end
alias_method_chain :call, :quiet_assets
end
end
Updated: It now works for Ruby on Rails 3.2 too (previous attempt fixes before_dispatch
, and now we're going for the root rack call
instead)
Update: A proper Rack middleware solution (instead of fragile alias_method_chain
) from @macournoyer https://github.com/rails/rails/issues/2639#issuecomment-6591735
rails with cucumber show unnecessary output
I was browsing around stack overflow, and today I
found a solution here -> https://stackoverflow.com/a/33987617/4394500
Basically, add
Rails.application.configure do
# ...
config.log_level = :info
end
to config/environments/test.rb
Rails console is not outputting SQL Statements to my Development Log
the rails console never writes to the log file, but you can achieve it quite easily, for example, if you execute following after starting the rails console
ActiveRecord::Base.logger = Logger.new STDOUT
rails will log all SQL statements to stdout, thus display them in your terminal.
and since Logger.new
accepts any stream as first argument, you could just let it write to the rails development.log:
ActiveRecord::Base.logger = Logger.new File.open('log/development.log', 'a')
Related Topics
How to Use Basic Authentication with Httparty in a Rails App
Concurrent Requests with Mri Ruby
Rails 4.1 Can't Deploy via Capistrano 3
If Else Statements in .Html.Erb in Views
How to View a Sample of the Call Stack in Ruby
How to Bypass Mass Assignment Protection
How to Handle Multiple Models in One Rails Form
How to Specify "Http Request Header" in Openuri
Bundle Install' Failed Due to Permission Denied
How to Output Names of Ruby Unit Tests
How to Add Child Nodes in Nodeset Using Nokogiri
Named Parameters in Ruby Structs
Turn Off Verbose SQL/Activerecord for Rails 3.1.1
Firebase Token Error, "The Custom Token Corresponds to a Different Audience."
How to Profile Ruby 1.9.2 Scripts with Memory Allocation Reports