Dangerous Rails Logging
You may have the habit of doing:
logger.debug "this wont print in production"
logger.debug "i'll just leave it in my code"
logger.debug "i'm told it's harmless"
But WAIT!
logger.debug "Are we there yet? #{Comment.count}"
Can be disastrous in production because the string is going to be evaluated in production too, it just wont be printed out.
So, you do this to be savvy
logger.debug { "Let's walk the database already #{Comment.count}" }
The block ensures that it wont be evaluated in production unless the severity level allows it.
Written by Aditya Sanghi
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#