为什么我无法在 Heroku 控制台中打印(“放置”)?
我有一个 Rails 应用程序部署到 heroku,需要在 heroku 控制台
中处理一些数据。为了帮助我做到这一点,我在 lib 目录中创建了 cmd.rb
,其中包含一些方法。这是它的样子:
class Cmd
def self.hello
puts "Hello World"
end
def self.create_member
# real code with multiple "puts" statements here
end
end
这是当我尝试在 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
上面明显缺少“Hello World”。现在,如果我在另一个终端窗口中执行此操作,我可以看到输出:
heroku logs --tail
但是该输出中有很多噪音,我希望能够逐步看到内容。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这可能是因为 Heroku 实现控制台的方式:
因此,一种解决方案可能是升级到 Cedar: http://devcenter.heroku.com/articles/cedar< /a>
另一种解决方案可能是禁用
rails_log_stdout
功能。我不知道该怎么做,但开票可能会得到解决方案。此外,您也许可以过滤日志结果。请参阅“过滤”:http://devcenter.heroku.com/articles/logging
I think it may be because of the way Heroku implemented the console:
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
我认为你应该尝试使用 Rails.logger 而不是方法“puts”。
I think you should try to use Rails.logger instead of the method 'puts'.