开发者

Why can't I print ("puts") in heroku console?

开发者 https://www.devze.com 2023-04-06 16:52 出处:网络
I have a Rails app deployed to heroku and need to munge some data in heroku console.To help me do this I\'ve created cmd.rb in my lib directory 开发者_运维技巧with some methods in it.Here\'s what it l

I have a Rails app deployed to heroku and need to munge some data in heroku console. To help me do this I've created cmd.rb in my lib directory 开发者_运维技巧with some methods in it. Here's what it looks like:

class Cmd
  def self.hello
    puts "Hello World"
  end

  def self.create_member
    # real code with multiple "puts" statements here
  end
end

And here's what I get when I try to run this in heroku console:

$ heroku console
Ruby console for myapp.heroku.com
>> puts User.count
515
=> nil
>> 3.times {|i| puts i}
0
1
2
=> 3
>> require "#{Rails.root}/lib/cmd"
=> true
>> Cmd
=> Cmd
>> Cmd.hello
=> nil

There's a notable lack of "Hello World" in the above. Now I can see the output if I do this in another terminal window:

heroku logs --tail

But there's a lot of noise in that output, and I'd like to be able to see things incrementally.


I think it may be because of the way Heroku implemented the console:

On Bamboo, heroku rake and heroku console were implemented as special-cased execution paths, with output delivered over HTTP. This approach has a number of weaknesses, such as timeouts and non-interactivity on rake tasks.

So, one solution might be to upgrade to Cedar: http://devcenter.heroku.com/articles/cedar

Another solution could be to disable the rails_log_stdout functionality. I didn't figure out how to do that, but opening a ticket may get a solution.

Also, you may be able to filter the log results. See 'Filtering': http://devcenter.heroku.com/articles/logging


I think you should try to use Rails.logger instead of the method 'puts'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号