When I code, I make quite intense use of “puts” statements for debugging. It allows me to see what happens in the server.
When the code is debugged, I use to remove these “puts” statements for I don’t know what reason.
Is it a good idea or should I leave them instead to give more clarity to my server logs?
You should use the logger instead of
puts. Use this kind of statements:If you want to see the debugging in the real-time (almost), just use the
tailcommand in another terminal window:Then you do not need to remove these statements in production, and they will not degrade performance too much, because
if logger.debug?will prevent the (possibly expensive) construction of the message string.Using standard output for debugging is usually a bad practice. In cases you need such debug, use the diagnostic
STDERR, as in:Most of the classes in Rails (models, controllers and views) have the method
logger, so if possible use it instead of the fullRails.logger.If you are using older versions of Rails, use the constant
RAILS_DEFAULT_LOGGERinstead ofRails.logger.