如何让我的 Rails 5 日志向我显示与 Rails 4 一样的每个操作的尽可能多的详细信息?

How do I get my Rails 5 log to show me as many details about each operation like Rails 4 did?

出于某种原因,即使在开发中,我的 Rails5 日志也只显示了一些信息。

我不确定它如何选择要显示的内容。

不知道是不是我装了Turbolinks的缘故,我怀疑。

在 Rails 5 over 4 中,Rails 记录开发请求的方式是否发生了变化?

编辑 1

这里很难完全展示,但这里有一个例子。

我重新启动了我的服务器,然后我访问了我的 root_path,即 questions#index。然后我去了一个个人问题question#show,然后我刷新了那个展示页面。这就是这 3 个请求的日志显示内容:

$ rails s
=> Booting Puma
=> Rails 5.0.0.rc1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.4.0 (ruby 2.3.0-p0), codename: Owl Bowl Brawl
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Started GET "/" for ::1 at 2016-05-16 16:08:03 -0500
  ActiveRecord::SchemaMigration Load (1.0ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by QuestionsController#index as HTML
  Rendering questions/index.html.erb within layouts/application
  Rendered shared/_main_page_heading.html.erb (0.3ms)
  Question Load (1.1ms)  SELECT "questions".* FROM "questions"
  User Load (1.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" IN (1521, 1522, 1523, 1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1536, 1537, 1538)
   (1.1ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 4]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 4]]
  Rendered questions/_question.html.erb (443.5ms)
   (1.9ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 5]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 5]]
  Rendered questions/_question.html.erb (5.2ms)
   (1.7ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 6]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 6]]
  Rendered questions/_question.html.erb (4.9ms)
   (1.9ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 7]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 7]]
  Rendered questions/_question.html.erb (5.0ms)
   (1.8ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 8]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 8]]
  Rendered questions/_question.html.erb (5.2ms)
   (1.7ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 9]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 9]]
  Rendered questions/_question.html.erb (5.0ms)
   (1.7ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 10]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 10]]
  Rendered questions/_question.html.erb (5.4ms)
   (2.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 11]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 11]]
  Rendered questions/_question.html.erb (5.7ms)
   (1.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 12]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 12]]
  Rendered questions/_question.html.erb (3.2ms)
   (1.6ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 13]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 13]]
  Rendered questions/_question.html.erb (5.0ms)
   (1.1ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 14]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 14]]
  Rendered questions/_question.html.erb (4.8ms)
   (1.4ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 15]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 15]]
  Rendered questions/_question.html.erb (4.9ms)
   (2.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 16]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 16]]
  Rendered questions/_question.html.erb (7.4ms)
   (2.2ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 17]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 17]]
  Rendered questions/_question.html.erb (6.6ms)
   (2.1ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 18]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 18]]
  Rendered questions/_question.html.erb (6.3ms)
   (1.1ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 19]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 19]]
  Rendered questions/_question.html.erb (3.9ms)
   (1.5ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 20]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 20]]
  Rendered questions/_question.html.erb (6.1ms)
   (1.2ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 21]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 21]]
  Rendered questions/_question.html.erb (3.6ms)
  Rendered questions/index.html.erb within layouts/application (621.0ms)
  Rendered shared/_navbar.html.erb (1.1ms)
Completed 200 OK in 1917ms (Views: 1844.9ms | ActiveRecord: 52.9ms)

只显示第一个操作,没有显示第二个

假设我停止了服务器,同时还在 /questions/4,然后重新启动它并刷新然后返回主页,这是日志显示的内容:

$ rails s
=> Booting Puma
=> Rails 5.0.0.rc1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.4.0 (ruby 2.3.0-p0), codename: Owl Bowl Brawl
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
Started GET "/questions/4" for ::1 at 2016-05-16 16:10:55 -0500
  ActiveRecord::SchemaMigration Load (1.4ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by QuestionsController#show as HTML
  Parameters: {"id"=>"4"}
  Question Load (1.1ms)  SELECT  "questions".* FROM "questions" WHERE "questions"."id" =  LIMIT   [["id", 4], ["LIMIT", 1]]
  Rendering questions/show.html.erb within layouts/application
  User Load (1.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" =  LIMIT   [["id", 1521], ["LIMIT", 1]]
   (2.2ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 4]]
  CACHE (0.0ms)  SELECT COUNT(*) FROM "answers" WHERE "answers"."question_id" =   [["question_id", 4]]
  Answer Load (2.8ms)  SELECT "answers".* FROM "answers" WHERE "answers"."question_id" =   [["question_id", 4]]
  User Load (3.1ms)  SELECT  "users".* FROM "users" ORDER BY RANDOM() LIMIT   [["LIMIT", 1]]
  Rendered answers/_form.html.erb (535.9ms)
  Rendered questions/show.html.erb within layouts/application (637.2ms)
  Rendered shared/_navbar.html.erb (1.2ms)
Completed 200 OK in 2666ms (Views: 2575.6ms | ActiveRecord: 34.4ms)

它不显示第二个请求,只显示第一个。可能是因为它正在被缓存,或者 Turbolinks 正在从我的缓存或其他东西中提供页面的最新版本,但关键是我根本没有看到请求到达我的服务器。

不确定如何让所有 2 或 3 个请求都显示在我的日志中。很难显示不显示的内容,但我希望这能更好地解释它。

您可以通过在 config/environments/.rb 文件中设置适当的日志级别来控制它,例如:

config.log_level = :调试

在使用 rails 5 rc1 和 puma 3.4.0 遇到同样的问题后,我发现问题与 quiet_assets gem having thread-safe issues 有关。 所以你的选择是:

更新

sprockets-rails 终于添加了 config.assets.quiet 选项。所以最终的解决方案是更新 sprockets-rails (和 rails 5 也因为终于有一个稳定的版本)并添加:

#config/environments/development.rb
config.assets.quiet = true