Question

In my Rails app, there are some cases where code is being outputted with the puts command (for debugging purposes). Is there anyway to follow this output in the rails console (with the rails c command)? Or is there any other way to debug/view logs in the rails console?

Thanks!

Was it helpful?

Solution 2

Rails.logger is the best solution,one more think i want to add,if you want separate log file you could use like this

def read(args)    
 unless args.blank?
   cache_key= self.get_cache_key(args)
 end
 logger = Logger.new("#{Rails.root}/log/cache_read.log")
 logger.error("cache read scope == #{cache_key.to_s}")
end

so cache_read.log file having only this method log only.

OTHER TIPS

For debugging, use Rails.logger instead of puts. For example:

Rails.logger.info "Some debugging info"

This will be logged to a log file in rails_app_root/log directory. If you are running in development environment locally, it will be logged to rails_app/log/development.log file.

Now, to see the log as they come in you can use tail command, like this:

tail -f log/development.log

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top