Set debugging instructions

When I code, I use the "puts" instructions quite a bit for debugging. This allows me to see what is happening on the server.

When the code is debugged, I use "puts" to delete these statements, because I don’t know what the reason is.

Is this a good idea or should I leave them instead to give more clarity to my server logs?

+5
source share
3 answers

You should use a registrar instead puts. Use the following statements:

Rails.logger.debug "DEBUG: #{self.inspect} #{caller(0).first}" if Rails.logger.debug?

If you want to see real-time debugging (almost), just use the command tailin another terminal window:

tail -F log/development.log | grep DEBUG

, , if logger.debug? (, ) .

. , , STDERR, :

STDERR.puts "DEBUG: xyzzy"

Rails (, ) logger, , , Rails.logger. Rails, RAILS_DEFAULT_LOGGER Rails.logger.

+20

rails_dt gem, .

Rails.logger puts , , (DEBUG, *** ..) , .

, , Rails.logger puts, , .

rails_dt (, ), . , DT.p , .

:

DT.p "Hello, world!"

# Sent to console, Rails log, dedicated log and Web page, if configured.
[DT app/controllers/root_controller.rb:3] Hello, world!

Gem .

+1

All Articles