如何查看Heroku中的详细日志,类似于我在开发环境中看到的日志?

时间:2013-01-01 00:26:58

标签: ruby-on-rails ruby-on-rails-3 heroku

在我的开发环境中,当我在我的应用上发出请求时,我会看到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 logs --tail跟踪我的Heroku日志,这就是我获取该信息的方式。

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

感谢。

修改

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

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

config/environment/production.rb我说了这个:

config.log_level = :debug

3 个答案:

答案 0 :(得分:5)

在较旧的堆栈上,Heroku会在您的应用中插入一个插件,重新配置记录器以适应Heroku的设置。此插件使用LOG_LEVEL环境变量来设置使用的日志记录级别(忽略应用程序配置中的任何内容)

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

使用当前堆栈,您应该使用rails_12factor gem,将日志输出重定向到stdout,Heroku希望在其中找到它。

答案 1 :(得分:2)

每个环境初始化程序({development,staging,production} .rb)中有一个log_level设置。在生产和暂存中,它可以是注释或设置为:info。将其设置为:debug。

另外,添加

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

到config / environment.rb的底部。

答案 2 :(得分:0)

将以下内容添加到production.rb

config.logger = Logger.new(STDOUT)