默认情况下,在Rails 3.1(RC1)下,链接在(dev)日志中往往非常冗长:
Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Compiled app/assets/stylesheets/application.css.scss (5ms) (pid 6303)
Started GET "/assets/application.js" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Compiled app/assets/stylesheets/default.css.scss (15ms) (pid 6303)
...
Started GET "/assets/default/header_bg.gif" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Served asset /default/header_logo.gif - 304 Not Modified (7ms) (pid 6303)
Served asset /default/header_bg.gif - 304 Not Modified (0ms) (pid 6246)
Served asset /default/footer_bg.gif - 304 Not Modified (49ms) (pid 6236)
...
我假设有一种干净的方法可以通过在 environment.rb
或 development.rb
中添加配置行来禁用或减少日志记录的详细程度,类似于 config.active_record.logger = nil
,这会使ActiveRecord SQL语句静音 .
14 回答
将以下代码放在
config/initializers/quiet_assets.rb
中更新:现在也适用于Rails 3.2(以前的尝试修复了
before_dispatch
现在我们要去根机架call
而不是)更新:来自@macournoyer的正确的Rack中间件解决方案(而不是脆弱的
alias_method_chain
)https://github.com/rails/rails/issues/2639#issuecomment-6591735看看https://github.com/evrone/quiet_assets并将其包含在您的Gemfile中
对于懒惰:
gem 'quiet_assets', group: :development
对于Rails 3.2,将
config.assets.logger = false
添加到开发环境配置文件中,通常位于config/environments/development.rb
. 见#4512最终,它将是
config.assets.logger = nil
但该部分目前存在于master(尚未完成)有两件事就足够了:
config.assets.debug = false
inconfig/enviroments/development.rb
rake assets:precompile
. See comment by @oma below; this is not needed就这样!
我知道这是一个丑陋的临时解决方案,但我用它:
许多人对
config.assets.logger = false
的使用感到困惑 . 这是它做什么,不做什么 .根据source documentation:
然而,这可能不是你认为的那样 . It only disables sprocket 'serving' logs ,而不是Rails actionpack请求日志 . Rails维护者在此解释清楚:https://github.com/rails/rails/issues/4569#issuecomment-3594500
以链接为例,这样的日志被禁用:
但是这样的日志不是
这是最新的方式 .
在config / environment的development.rb中,你会找到
config.assets.debug = true
行 . 切换到false
并且大部分资产负载输出都将消失 . 在我的系统上,只有application.css和.js的两个请求仍然存在 .这是@choonkeat添加的相同代码 . 我刚刚也包括在windows下工作 .
在config / environments / development.rb中,请添加:
config.assets.debug = false
config.assets.logger = false
这有助于解决您的问题 .
Lograge for win-它可以立即杀死Rails恼人的 Logger 默认值(例如记录资产,记录部分渲染),并且如果要添加/删除特定项目,则可以自定义 .
以下提到的链接解决方案有助于
https://github.com/evrone/quiet_assets
同样如下,它对我来说很好
3.1(仅)(3.2 break before_dipatch)
在config / environments中,将
config.log_level = :error
添加到要更改的.rb文件中 . 这会将日志设置更改为仅错误 . 我希望这有帮助!