Rails 3.2.x: How to change logging levels without restarting the application

logging, ruby-on-rails-3

Solution

As you have to change the level in the running rails instance, a simple rake task will not work. I would go with the dedicated route.

instead of a shared secret I would use the app's standard user authentication (if your app has users) and restrict access to admin/super user.

Problem

I would like to change the logging levels of a running Rails 3.2.x application without restarting the application. My intent is to use it to do short-time debugging and information gathering before reverting it to the usual logging level. I also understand that the levels in ascending order are debug, info, warn, error, and fatal, and that production servers log info and higher, while development logs debug and higher. I understand that if I run ``` Rails.logger.level=:debug #or :info, :warn, :error, :fatal ``` Will this change the logging level immediately? If so, can I do this by writing a Rake task to adjust the logging level, or do I need to support this by adding a route? For example in config/routes.rb: ``` match "/set_logging_level/:level/:secret" => "logcontroller#setlevel" ``` and then setting the levels in the logcontroller. (:level is the logging level, and :secret which is shared between client and server, is something to prevent random users from tweaking the log levels) Which is more appropriate, rake task or /set_logging_level?

Original source