如何从日志中忽略Rails 3资产[重复]

时间:2022-01-27 00:23:32

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

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

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

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

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!

谢谢!

4 个解决方案

#1


5  

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

显然,该问题自2011年11月2日起仍未解决。

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

在类似的问题中提供了一种解决方案:如何在Rails 3.1中禁用资产管道(链轮)消息的记录?

#2


11  

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

我认为这可以帮助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.

从当前版本的rails中使用的sprockets-rails版本3.1.0开始,不推荐使用此gem。

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

相关公关: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:

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

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...

支持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:

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

config.quiet_assets = false

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

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

config.quiet_assets_paths << '/silent/'

#3


5  

How about an invert selection?

反转选择怎么样?

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

tail -f log / development.log | grep -v资产

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

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

#4


0  

Rails 3.2:

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

从这里:https://github.com/rails/rails/issues/2639

#1


5  

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

显然,该问题自2011年11月2日起仍未解决。

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

在类似的问题中提供了一种解决方案:如何在Rails 3.1中禁用资产管道(链轮)消息的记录?

#2


11  

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

我认为这可以帮助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.

从当前版本的rails中使用的sprockets-rails版本3.1.0开始,不推荐使用此gem。

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

相关公关: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:

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

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...

支持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:

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

config.quiet_assets = false

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

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

config.quiet_assets_paths << '/silent/'

#3


5  

How about an invert selection?

反转选择怎么样?

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

tail -f log / development.log | grep -v资产

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

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

#4


0  

Rails 3.2:

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

从这里:https://github.com/rails/rails/issues/2639