Developer
Developer

Reputation: 661

Rails.logger.debug or puts?

I have been using this "puts" for checking some values in production, then i can see that in logs, so which one is the best way to get that in production logs, is it "Rails.logger.debug" or "puts"

Upvotes: 0

Views: 1239

Answers (1)

kiddorails
kiddorails

Reputation: 13014

Use Rails.logger. Logger comes with different levels (from 0 to 5) like:

  1. Debug
  2. Info
  3. Warn
  4. Error
  5. Fatal
  6. Unknown

Logging will help you to tag the message nicely and in the file, it then appears in proper log format (with timestamps and request_ids if enabled).

This is useful when you want to log under development or staging without flooding your production log with unnecessary information.

puts will not give all the above flexibility. If you are using either from development debugging point of view, it doesn't matter much, but I would still prefer Rails.logger for request_id tagging purposes :)

Upvotes: 4

Related Questions