I love digging through the docs and finding an example that kind of explodes your brain a bit—some piece of functionality you might otherwise gloss over.
Take this one from the Rails docs for log_at
. At first glance, I didn’t realize how useful this could be. Logging at different levels might be useful in some controllers, maybe? But seeing this example really crystallized it in a different way:
# Use the debug log level if a particular cookie is set.
class ApplicationController < ActionController::Base
log_at :debug, if: -> { cookies[:debug] }
end
Drop a cookie, and suddenly you’re getting debug-level logs for just that session—without touching global log settings!
It’s easy to imagine adding a button in an admin interface to toggle this or setting it via a query param (?debug=true
) that writes the cookie.
If you have usage of this in other clever ways, I’d love to know! Drop a comment!