Last Updated: February 25, 2016
·
803
· asanghi

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.