在生产模式下运行Rails应用程序时,终端未显示生产服务器日志,并在浏览器中显示错误“出现了错误”。

4
当我以开发模式运行Rails应用程序时,服务器日志能够在终端正常显示。但是当我以生产模式运行应用程序时,服务器没有在终端显示任何服务器日志,并且浏览器中显示错误消息:“抱歉,出现了一些问题。” 我使用以下命令运行服务器,并且使用thin服务器。
rails s -e production

当我启动服务器时,这是我在服务器模式下获得的输出。在此之后,当我发出任何请求时,没有输出显示。

prashant@prashant-pc:~/client_proj/template$ rails s -e production
=> Booting Thin
=> Rails 4.1.5 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[DEPRECATION] requiring "RMagick" is deprecated. Use "rmagick" instead
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:3000, CTRL+C to stop

我不太明白你的意思,请提供更多上下文或详细说明您需要翻译的内容。

production.rb 文件中,config.log_level 设置为什么? - Deepesh
config.log_level = :info - John
尝试将其设置为 :debug,不确定是否有帮助,只是一次尝试。然后重新启动服务器并进行测试。 - Deepesh
我尝试过了,但没有用。问题仍然存在,没有改变。 - John
请检查是否有必要的权限来创建和写入production.log文件。 - Sabyasachi Ghosh
3个回答

3
production.rb中,您可以添加以下选项:config.logger = Logger.new(STDOUT)

2
如果您在production.rb文件中看到此代码块:
  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger    = ActiveSupport::TaggedLogging.new(logger)
  end

那么在启动rails server之前,您可以使用export将环境变量设置为任何值。

$ export RAILS_LOG_TO_STDOUT=true

0

设置环境变量RAILS_ENV=productionRAILS_LOG_TO_STDOUT=true对我很有帮助(使用Rails 7.0.4)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接