Jak wyłączyć rejestrowanie komunikatów asset pipeline (sprockets) w Rails 3.1?
Sprockets zazwyczaj są dość gadatliwe w (dev) Logie domyślnie pod Rails 3.1 (RC1):
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)
...
Chciałbym albo zmniejszyć poziom szczegółowości, albo całkowicie ją wyłączyć.
Zakładam, że istnieje czysty sposób na wyłączenie lub zmniejszenie szczegółowości logowania przez dodanie linii konfiguracyjnej w environment.rb
lub development.rb
podobnej do config.active_record.logger = nil
, która wycisza polecenia ActiveRecord SQL. 14 answers
Umieść następujący kod w config/initializers/quiet_assets.rb
if Rails.env.development?
Rails.application.assets.try(: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'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
Rails.logger.level = previous_level
end
alias_method_chain :call, :quiet_assets
end
end
Zaktualizowano: teraz działa również dla Rails 3.2 (poprzednie poprawki before_dispatch
teraz zamiast tego wybieramy root rack call
)
Update: odpowiednie rozwiązanie Rack middleware (zamiast fragile alias_method_chain
) od @ macournoyer https://github.com/rails/rails/issues/2639#issuecomment-6591735
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-01 12:30:00
Spójrz na https://github.com/evrone/quiet_assets i po prostu dołącz go do swojego Gemfile
Dla leniwych: gem 'quiet_assets', group: :development
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-14 09:51:37
Dla Rails 3.2, dodaj config.assets.logger = false
do pliku konfiguracyjnego środowiska programistycznego, zazwyczaj znajdującego się pod adresem config/environments/development.rb
. Zobacz też #4512
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-20 18:05:48
W końcu będzie to config.assets.logger = nil
ale ta część jest obecnie stubowana NA master (jeszcze nie zrobiona)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-10 22:03:15
Dwie rzeczy wystarczą:
1. config.assets.debug = false
in config/enviroments/development.rb
2. rake assets:precompile
. Zobacz komentarz @oma poniżej; to nie jest potrzebne
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-31 02:16:58
Wiem, że to brzydkie i tymczasowe rozwiązanie, ale używam tego:
Tail - f log / development.log / grep-vE 'asset'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-08 16:17:34
Wiele osób jest zdezorientowanych co do używania config.assets.logger = false
. Oto, co robi, a czego nie.
Według dokumentacja źródłowa :
Ustawienie
config.assets.logger
Na false wyłączy rejestrowanie obsługiwanych zasobów.
Jednak to prawdopodobnie nie jest to, co myślisz, że jest. wyłącza tylko "serwowanie" logów sprocket , nie rejestry żądań Rails actionpack. Opiekun Rails wyjaśnia to wyraźnie tutaj: https://github.com/rails/rails/issues/4569#issuecomment-3594500
Biorąc przykład z linku, logi takie jak ten są wyłączone:
Serwowane aktywa / jquery.izotop.js-304 Nie zmodyfikowany (0ms)
Ale takie logi nie są
Rozpoczął GET " / assets / jquery.izotop.js?body= 1 " dla 127.0.0.1 at 2012-01-20 23:16:46 -0500
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-17 06:34:24
config.assets.quiet = true
/ Align = "left" /Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-08-11 21:51:27
W rozwoju.rb w config / environments znajdziesz linię config.assets.debug = true
. Przełącz to na false
, a większość danych wyjściowych obciążenia zasobów zniknie. W moim systemie tylko dwa wnioski o podanie.css i .js zostaje.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-07 08:59:05
Rails.application.assets.logger = Logger.new(RUBY_PLATFORM =~ /(win|w)32$/ ? "NUL" : "/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
To ten sam kod, który dodał @ choonkeat. Włączyłem również pracę pod Windowsem.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-02-07 16:00:54
W config / environments / development.rb proszę dodać:
config.assets.debug = false
config.assets.logger = false
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-16 16:37:05
Lograge dla wygranej-zabija irytujące domyślne logowanie Rails (np. rejestrowanie zasobów, rejestrowanie częściowego renderowania) i jest konfigurowalne, jeśli chcesz dodać / usunąć określone elementy.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-07 14:43:54
Poniższe rozwiązanie link pomaga:
Https://github.com/evrone/quiet_assets
Również jak poniżej działa dobrze dla mnie
3.1 (only) (3.2 breaks before_dipatch)
app\config\initializers\quiet_assets.rb
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def before_dispatch_with_quiet_assets(env)
before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index("/assets/") == 0
end
alias_method_chain :before_dispatch, :quiet_assets
end
3.2 Rails - Rack root tap approach
app\config\initializers\quiet_assets.rb
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
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-11 12:57:21
W config / environments dodaj config.log_level = :error
dopliki rb, które chcesz zmienić. Spowoduje to zmianę ustawień dziennika na błąd.
Mam nadzieję, że to pomogło!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-01 12:11:18