即使log_level设置为debug,rails 4.2也不能在heroku日志中看到db查询 [英] rails 4.2 can't see db queries in heroku logs even though log_level set to :debug

查看:180
本文介绍了即使log_level设置为debug,rails 4.2也不能在heroku日志中看到db查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在研究的项目: https://github.com/homanchou/the_drawing_challenge

Here is a project I'm working on: https://github.com/homanchou/the_drawing_challenge

我在使用Foreman运行Puma时在服务器日志中查看任何数据库查询时遇到问题,甚至无法在终端本地查看。

I'm having trouble seeing any db queries in the server logs on heroku or even locally in the terminal when running Puma with Foreman.

所有我看到的都是资产或网页请求

All I see are asset or web requests

21:54:34 web.1  | started with pid 54784
21:54:35 web.1  | [54784] Puma starting in cluster mode...
21:54:35 web.1  | [54784] * Version 2.10.2 (ruby 2.1.5-p273), codename: Robots on Comets
21:54:35 web.1  | [54784] * Min threads: 1, max threads: 4
21:54:35 web.1  | [54784] * Environment: development
21:54:35 web.1  | [54784] * Process workers: 2
21:54:35 web.1  | [54784] * Preloading application
21:54:36 web.1  | [54784] * Listening on tcp://0.0.0.0:5000
21:54:36 web.1  | [54784] Use Ctrl-C to stop
21:54:36 web.1  | [54784] - Worker 0 (pid: 54785) booted, phase: 0
21:54:36 web.1  | [54784] - Worker 1 (pid: 54786) booted, phase: 0
21:54:43 web.1  | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:43 -0700] "GET / HTTP/1.1" 200 - 0.3120
21:54:43 web.1  | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:43 -0700] "GET /logo_header.png HTTP/1.1" 304 - 0.0079
21:54:45 web.1  | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:45 -0700] "GET /challenges/8 HTTP/1.1" 200 - 0.0443
21:54:45 web.1  | [54785] 127.0.0.1 - - [02/Apr/2015:21:54:45 -0700] "GET /logo_header.png HTTP/1.1" 304 - 0.0067

我必须将另一行添加到Procfile log中:tail -f -n 0 log / development.log 在标准输出 foreman start 中查看日志或错误,就像我平时所做的那样,但是这只适用于本地,并且不适用于heroku,除非我想扩展该尾随的进程。

I had to add another line to the Procfile log: tail -f -n 0 log/development.log to see logs or errors in stdout of foreman start like I normally do, but that only works locally and not on heroku unless I want to scale up a process for that tailing.

在我的其他rails项目中,我可以看到db查询很好,即使在heroku上,我也可以在日志中看到db查询:

In my other rails project I can see the db queries fine, even on heroku I can see the db queries in the log:

2015-04-03T03:46:40.052067+00:00 app[web.1]: Started GET "/api/notifications/unread_count" for 97.93.34.8 at 2015-04-03 03:46:40 +0000
2015-04-03T03:46:40.070865+00:00 app[web.1]:   Merchant Load (2.7ms)  SELECT  "merchants".* FROM "merchants" WHERE "merchants"."id" = $1  ORDER BY "merchants"."id" ASC LIMIT 1  [["id", 7502]]
2015-04-03T03:46:40.085454+00:00 app[web.1]:   SQL (2.3ms)  UPDATE "merchants" SET "updated_at" = '2015-04-03 03:46:40.074442', "last_active_at" = '2015-04-03 03:46:40.074442' WHERE "merchants"."id" = $1  [["id", 7502]]
2015-04-03T03:46:40.101382+00:00 app[web.1]:    (2.3ms)  SELECT COUNT(*) FROM "notifications" WHERE "notifications"."merchant_id" = $1 AND "notifications"."state" = $2  [["merchant_id", 7502], ["state", "unread"]]
2015-04-03T03:46:40.058083+00:00 app[web.1]: Processing by NotificationsController#unread_count as JSON
2015-04-03T03:46:40.073916+00:00 app[web.1]:    (1.0ms)  BEGIN
2015-04-03T03:46:40.093737+00:00 app[web.1]:    (7.4ms)  COMMIT
2015-04-03T03:46:40.102858+00:00 app[web.1]: Completed 200 OK in 45ms (Views: 0.2ms | ActiveRecord: 15.6ms)

我尝试过比较这两个,甚至复制一些环境配置,但我仍然可以不知道。我试过在生产环境中设置config.log_level =:debug。我可以在ruby控制台中看到db查询,但不能在终端中看到heroku或本地puma标准输出。我缺少什么?

I tried comparing the two and even copying over some environment configurations but I still can't figure it out. I've tried setting config.log_level = :debug on the production environment. I can see db queries in the ruby console, but not the heroku or local puma stdout in the terminal. What am I missing?

推荐答案

如果您需要使用puma for websockets等,请尝试添加

If you need to use puma for websockets etc try adding

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

到您的environments.rb或environments / production

to your environments.rb or environments/production

这篇关于即使log_level设置为debug,rails 4.2也不能在heroku日志中看到db查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆