A very simple question is ruby ​​/ sinatra / heroku / debugging: how to see the output of puts and p?

I am trying to create a very simple synatra application deployed on heroku.

our application does not output material to a web browser; it communicates with another computer through the API. so my usual trick just printing a little extra info about debugging in the browser while I use the application doesn't work.

The sample code I saw for related applications shows several β€œputs” or β€œp” expressions that are used to see what happens ...

where the output is output, that I can see that the output is executed by the program or after that.

and in general, if you come across a code hosted in Heroku that just doesn’t do what you want, the easiest way is in different places of the code output messages, such as "foo equals 123", so you can see this output, to find out what is going on in the code?

p and puts the dont output, so the logs that I can see when I print "hero logs", for example ...

+7
source share
5 answers

According to http://docs.heroku.com/logging you should have puts and p , just go to your log if you add a basic logger (which apparently was added by default for all applications created after February 2, 2011 g.).

For a base file without binding to Heroku with Sinatra and Logger:

 require 'logger' Dir.mkdir('logs') unless File.exist?('logs') $log = Logger.new('logs/output.log','weekly') configure :production do $log.level = Logger::WARN end configure :development do $log.level = Logger::DEBUG end get "/" do $log.debug "Hello, World!" end 
+4
source

If you use a cedar stack, try putting the line below in config.ru,

 $stdout.sync = true 

http://devcenter.heroku.com/articles/ruby#logging

The original post was in February 2011, and the Cedar stack was introduced in May, so this doesn't seem like help for the original question, but some of you may find that it might be help. http://blog.heroku.com/archives/2011/5/31/celadon_cedar/

+10
source

This will work fine. test_logging.rb

 require 'sinatra' require 'logger' enable :logging before do logger.level = Logger::DEBUG end get '/' do logger.debug "Handling 'hello world' request." logger.info "Hello world." return "<h1>Hello World</h1>" end 
+3
source

See here for tips on how to write in Logger: http://mikenaberezny.com/2007/02/24/rails-logging-tips/

The given example:

 class HomeController < ActionController::Base def index logger.info 'informational message' end end 
0
source

This is the line that works for me:

 # On config.ru, before run: enable :logging, :dump_errors, :raise_errors 
0
source

All Articles