gpt4 book ai didi

ruby-on-rails - 充满 GET 请求的 Rails 开发日志,只想查看数据库请求

转载 作者:行者123 更新时间:2023-12-04 05:49:24 26 4
gpt4 key购买 nike

我的 Rails 开发日志中有大量这样的行:

Started GET "/assets/services.css?body=1" for 127.0.0.1 at 2012-11-26 02:27:49 -0800
Served asset /services.css - 304 Not Modified (0ms)
[2012-11-26 02:27:49] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

我想我需要弄清楚如何让 rails 确定内容长度或在某处设置 response.chunked(不确定那是什么)以避免最后一行。但是,绝大多数时间我不得不浪费时间搜索这些以找到这样的数据库请求:

Started GET "/points" for 127.0.0.1 at 2012-11-26 02:27:54 -0800
Processing by PointsController#index as HTML
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
PointsLog Load (0.1ms) SELECT "points_logs".* FROM "points_logs" WHERE "points_logs"."user_id" = 1
Rendered points/index.html.erb within layouts/application (5.4ms)
Completed 200 OK in 43ms (Views: 40.0ms | ActiveRecord: 0.8ms)

我可以查看这些类型的请求的单独日志吗?有没有办法暂时甚至永久地抑制以“服务 Assets ”开头的日志条目?或者只是不记录服务 Assets ?

最佳答案

更新:自从我写了下面的内容后,有人制作了一个可以做同样事情的 gem。可能是更好的方法。 https://rubygems.org/gems/quiet_assets

将其放入 config/initializers/quiet_assets.rb 并重新启动您的开发服务器。

#
#
# Silence the log file if it's loading up an asset. That is, get rid of
# the following types of entries in the development log:
#
# Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-03-05 11:52:18 -0800
# Served asset /application.css - 200 OK (5ms)
#
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
alias_method_chain :call, :quiet_assets
end

关于ruby-on-rails - 充满 GET 请求的 Rails 开发日志,只想查看数据库请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13571552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com