简体   繁体   中英

How do I see detailed logs in Heroku, similar to the logs I see in my dev environment?

In my dev environment, when I make a request on my app, I see the AREL & SQL queries like this:

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)

But this is the same query on 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

I am tailing my Heroku logs by doing heroku logs --tail , that's how I am getting that info.

Is it possible to get the same type of logs that I see in my dev environment on Heroku?

Thanks.

Edit:

In my config/environment.rb I put this:

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

In config/environment/production.rb I put this:

config.log_level = :debug

On older stacks, Heroku inserts a plugin into your app that reconfigures the logger to fit into Heroku's setup. This plugin uses the LOG_LEVEL environment variable to set the logging level used (whatever is in your app's config is ignored)

Update that environment variable to DEBUG and you should see the extra info.

With current stacks, you should use the rails_12factor gem, that redirects log output to stdout, where Heroku expects to find it.

There's a log_level setting in the per environment initializers ({development,staging,production}.rb). In production and staging it is either commented or set to :info. Set it to :debug.

Also, add

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

to the bottom of your config/environment.rb.

将以下内容添加到production.rb

config.logger = Logger.new(STDOUT)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM