[英]Why can't I print (“puts”) in heroku console?
I have a Rails app deployed to heroku and need to munge some data in heroku console
. 我有一个部署到heroku的Rails应用程序,需要在
heroku console
挖掘一些数据。 To help me do this I've created cmd.rb
in my lib directory with some methods in it. 为了帮助我这样做,我在我的lib目录中创建了
cmd.rb
,其中包含一些方法。 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控制台中运行时获得的内容:
$ 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. 上面有一个明显缺乏“Hello World”。 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: 我想这可能是因为Heroku实现控制台的方式:
On Bamboo, heroku rake and heroku console were implemented as special-cased execution paths, with output delivered over HTTP.
在Bamboo上,heroku rake和heroku控制台实现为特殊的执行路径,输出通过HTTP传递。 This approach has a number of weaknesses, such as timeouts and non-interactivity on rake tasks.
这种方法有许多缺点,例如rake任务的超时和非交互性。
So, one solution might be to upgrade to Cedar: http://devcenter.heroku.com/articles/cedar 因此,一种解决方案可能是升级到Cedar: http : //devcenter.heroku.com/articles/cedar
Another solution could be to disable the rails_log_stdout
functionality. 另一种解决方案可能是禁用
rails_log_stdout
功能。 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
请参阅“过滤”: http : //devcenter.heroku.com/articles/logging
我认为你应该尝试使用Rails.logger而不是'puts'方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.