Ruby-on-rails Heroku 调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5994492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Heroku debugging
提问by AdamGold
I am building an application with Heroku and having some problems. I want to debug some content like I do with rails server:
我正在使用 Heroku 构建应用程序并遇到一些问题。我想像使用 rails 服务器一样调试一些内容:
logger.debug '...'
logger.debug '...'
How can I do that in Heroku, so I can see the debugging in heroku logs? (or anything else..)
我怎样才能在 Heroku 中做到这一点,以便我可以在 heroku 日志中看到调试?(或其他任何东西..)
Thanks!
谢谢!
采纳答案by Tam
Details here: http://devcenter.heroku.com/articles/logging
详情请见:http: //devcenter.heroku.com/articles/logging
Also make sure you set the right Logging level for your Rails app: http://blog.sethladd.com/2005/11/adjust-log-level-in-ruby-on-rails.html
还要确保为 Rails 应用程序设置正确的日志记录级别:http: //blog.sethladd.com/2005/11/adjust-log-level-in-ruby-on-rails.html
回答by Blockpusher
The Cedar stack in Heroku does not appear to be responsive to the LOG_LEVEL config (env) variable that works for previous stacks (I use the logging:expanded addon). I tried setting LOG_LEVEL to both debugand DEBUGwithout success.
Heroku 中的 Cedar 堆栈似乎对适用于以前堆栈的 LOG_LEVEL 配置 (env) 变量没有响应(我使用 logging:expanded 插件)。我尝试将 LOG_LEVEL 设置为两者debug,DEBUG但没有成功。
Only by setting config.log_level = :debugin config/environments/production.rb am I able to see the output of 'logger.debug'.
只有通过config.log_level = :debug在 config/environments/production.rb 中设置,我才能看到“logger.debug”的输出。
回答by Michael Schmitz
Been fighting with this for a long time, solution is nice and simple:
与此斗争了很长时间,解决方案既简单又好:
Set in production.rb instead of
在 production.rb 中设置而不是
config.log_level = :debug
place:
地方:
config.logger = Logger.new(STDOUT)
config.logger.level = Logger::DEBUG
and you get the full logging output.
你会得到完整的日志输出。
回答by Douglas F Shearer
heroku logson your command line will give you the logs for the current app. If you have expanded loggingturned on you can tail this output
heroku logs在您的命令行上将为您提供当前应用程序的日志。如果您打开了扩展日志记录,则可以拖尾此输出
回答by Jerry Clinesmith
Using Rails 3.2, we made this configurable by modifying config/environments/{environment}.rbto drive it from an environment variable:
使用 Rails 3.2,我们通过修改config/environments/{environment}.rb以从环境变量驱动它来实现它的可配置:
config.log_level = ENV["LOG_LEVEL"].to_sym if ENV["LOG_LEVEL"]
Then, we can modify the Heroku config variable to change it:
然后,我们可以修改 Heroku 配置变量来更改它:
heroku config:set LOG_LEVEL=debug --app <app name>
This lets us easily log more or less as needed.
这让我们可以轻松地根据需要或多或少地记录日志。
回答by Steven Soroka
This worked for me:
这对我有用:
heroku config:set LOG_LEVEL=debug
回答by user664833
To write to your logs on Heroku, instead of using logger.debug "..."simply use puts:
要在 Heroku 上写入您的日志,而不是logger.debug "..."简单地使用puts:
puts "..."
You don'teven need to set the config.log_levelsetting in config/environments/production.rb.
你不甚至需要设置config.log_level的设定config/environments/production.rb。
回答by Omer
config.log_level = ENV['APP_LOG_LEVEL'] ? ENV['APP_LOG_LEVEL'].to_sym : :error

