如何从日志中忽略 Rails 3 资产

发布于 2024-12-03 16:50:07 字数 471 浏览 3 评论 0原文

可能的重复:
如何禁用资产日志记录Rails 3.1 中的管道(链轮)消息?

是否可以破解 Rails3 中的记录器以忽略对资产的请求?

当日志里写满了

Started GET "/assets/tiscali.png" for 127.0.0.1 at 2011-09-09 19:59:45 +0200
Served asset /tiscali.png - 304 Not Modified (0ms)

“谢谢”时,在日志中找到一些东西真是太疯狂了!

Possible Duplicate:
How to disable logging of asset pipeline (sprockets) messages in Rails 3.1?

is possible to hack logger in Rails3 to ignore requests for assets?

It is maddness to find something in log, when it is full of

Started GET "/assets/tiscali.png" for 127.0.0.1 at 2011-09-09 19:59:45 +0200
Served asset /tiscali.png - 304 Not Modified (0ms)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水水月牙 2024-12-10 16:50:07

我认为这可能会有所帮助 https://github.com/evrone/quiet_assets

弃用

从当前版本的 Rails 中使用的 sprockets-rails 版本 3.1.0 开始,此 gem 已被弃用。

资产管道现在支持quiet选项,该选项可以抑制资产请求的输出:

<前><代码># config/environments/development.rb

config.assets.quiet = true

相关 PR:https://github.com/rails/sprockets-rails/pull /355

信息

安静资产会关闭 Rails 资产管道日志。这意味着它会抑制开发日志中的消息,例如:

于 2015-01-28 13:35:34 +0300 开始获取 127.0.0.1 的“/assets/application.js”
服务资产 /application.js - 304 未修改(8 毫秒)

支持 Ruby on Rails >= 3.1...

用法

只需安装安静资产即可自动抑制日志消息。但是,如果您希望暂时重新启用资产管道消息的日志记录,请将以下内容放入您的 config/application.rb 文件中:

config.quiet_assets = false

如果您需要抑制其他路径的输出,可以通过指定来实现:

config.quiet_assets_paths << '/沉默的/'

I think this could help https://github.com/evrone/quiet_assets

Deprecation

As of sprockets-rails version 3.1.0, used in current versions of rails, this gem is deprecated.

The asset pipeline now supports a quiet option which suppresses output of asset requests:

# config/environments/development.rb

config.assets.quiet = true

Relevant PR: https://github.com/rails/sprockets-rails/pull/355

Info

Quiet Assets turns off the Rails asset pipeline log. This means that it suppresses messages in your development log such as:

Started GET "/assets/application.js" for 127.0.0.1 at 2015-01-28 13:35:34 +0300
Served asset /application.js - 304 Not Modified (8ms)

Support Ruby on Rails >= 3.1...

Usage

Simply installing Quiet Assets will suppress the log messages automatically. However, if you wish to temporarily re-enable the logging of the asset pipeline messages, place the following in your config/application.rb file:

config.quiet_assets = false

If you need to suppress output for other paths you can do so by specifying:

config.quiet_assets_paths << '/silent/'
眼趣 2024-12-10 16:50:07

显然,截至 2011 年 11 月 2 日,问题 仍然处于开放状态。

解决方案可在类似的问题:如何禁用资产管道的日志记录( Rails 3.1 中的链轮)消息?

Apparently the issue is still open as of 02 Nov 2011.

A workaround solution is available in a similar question: How to disable logging of asset pipeline (sprockets) messages in Rails 3.1?

超可爱的懒熊 2024-12-10 16:50:07

反向选择怎么样?

tail -f log/development.log | tail -f log/development.log | grep -v asset

这基本上输出除了包含单词“asset”的行之外的所有内容。

How about an invert selection?

tail -f log/development.log | grep -v asset

This basically outputs everything except for the lines that contain the word "asset".

陌伤ぢ 2024-12-10 16:50:07

Rails 3.2:

使用以下内容创建初始化程序:

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 

从此处: https://github.com/rails/导轨/问题/2639

Rails 3.2:

create a initializer with the content:

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 

From here: https://github.com/rails/rails/issues/2639

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文