2

在我的开发环境中,当我在我的应用程序上发出请求时,我会看到如下 AREL 和 SQL 查询:

Started GET "/products/20" for 127.0.0.1 at 2012-12-31 19:18:40 -0500
Processing by ProductsController#show as HTML
  Parameters: {"id"=>"20"}
  Category Load (0.2ms)  SELECT "categories".* FROM "categories" LIMIT 6
  Product Load (0.1ms)  SELECT "products".* FROM "products" WHERE "products"."id" = ? LIMIT 1  [["id", "20"]]
  Product Load (0.3ms)  SELECT "products".* FROM "products" 
  Vendor Load (0.2ms)  SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
  Product Load (0.2ms)  SELECT "products".* FROM "products" WHERE "products"."vendor_id" = 11
   (0.2ms)  SELECT COUNT(*) FROM "categories" INNER JOIN "category_products" ON "categories"."id" = "category_products"."category_id" WHERE "category_products"."product_id" = 20
  Category Load (0.1ms)  SELECT "categories".* FROM "categories" INNER JOIN "category_products" ON "categories"."id" = "category_products"."category_id" WHERE "category_products"."product_id" = 20
  CACHE (0.0ms)  SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
  CACHE (0.0ms)  SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" = 11 LIMIT 1
  Rendered products/_similar_products.html.erb (6.1ms)
  Rendered products/show.html.erb within layouts/application (71.2ms)
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
   (0.2ms)  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = 1 AND (((roles.name = 'superadmin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))
  Rendered layouts/_login_nav.html.erb (5.1ms)
  Rendered layouts/_navigation.html.erb (0.9ms)
  Rendered layouts/_header.html.erb (76.4ms)
  Rendered layouts/_messages.html.erb (0.3ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 1171ms (Views: 1160.9ms | ActiveRecord: 1.9ms)

但这是在 Heroku 上的相同查询:

2013-01-01T00:24:57+00:00 app[web.1]: Started GET "/products/20" for 67.230.41.62 at 2013-01-01 00:24:57 +0000
2013-01-01T00:24:58+00:00 heroku[router]: at=info method=GET path=/products/20 host=myapp.herokuapp.com fwd=67.230.41.62 dyno=web.1 queue=0 wait=0ms connect=1ms service=59ms status=200 bytes=7718

我正在跟踪我的 Heroku 日志heroku logs --tail,这就是我获取该信息的方式。

是否可以获得与我在 Heroku 开发环境中看到的相同类型的日志?

谢谢。

编辑:

在我的config/environment.rb我放了这个:

ActiveRecord::Base.logger.level = Logger::DEBUG

config/environment/production.rb我放这个:

config.log_level = :debug
4

3 回答 3

5

在较旧的堆栈上,Heroku 会在您的应用程序中插入一个插件,以重新配置记录器以适应 Heroku 的设置。这个插件使用LOG_LEVEL环境变量来设置使用的日志级别(无论你的应用程序的配置是什么都被忽略)

将该环境变量更新为 DEBUG,您应该会看到额外的信息。

对于当前的堆栈,您应该使用rails_12factorgem,它将日志输出重定向到标准输出,Heroku 期望在其中找到它。

于 2013-01-02T07:32:38.623 回答
2

每个环境初始化程序({development,staging,production}.rb)中有一个 log_level 设置。在生产和登台中,它要么被注释,要么被设置为 :info。将其设置为:调试。

另外,添加

ActiveRecord::Base.logger.level = Logger::DEBUG

到 config/environment.rb 的底部。

于 2013-01-01T00:36:57.217 回答
0

将以下内容添加到 production.rb

config.logger = Logger.new(STDOUT)
于 2013-03-26T11:37:47.480 回答