How to ignore Rails 3 assets from log [duplicate] - ruby-on-rails

This question already has answers here:
Closed 10 years ago.
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!

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/'

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?

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

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

Related

Grails Asset Pipeline - minifyJs set to true not working

I used grails asset pipeline plugin to minify my application (I don't have any problem when running grails run-app) the problem arises when I'm going to generate a war file to deploy into tomcat server.
Currently using ':asset-pipeline:1.9.9'
currently My Config.groovy has this setup
grails.assets.minifyJs = true
grails.assets.minifyCss = true
grails.assets.bundle = true
The Particular problem here is when I'm going to set minifyJs = true
when I'm going to set minifyJs = false there's no error but my war file are not going to work when deployed to tomcat server.
| Error 2016-03-13 01:50:16,590 [main] ERROR pipeline.AssetCompiler - Uglify JS Exception
Message: [object Object] (/application/target/work/resources/uglifyjs/lib/parse-js.js#273)
Line | Method ->> 273 | _c_js_error_13 in org.mozilla.javascript.gen._application_target_work_resources_uglifyjs_lib_parse_js_js_2
I don't know whats going on or I missed something?
Immediately above the error message lines you quoted should be lines like this:
| Processing File 851 of 888 - jquery/src/intro.js
| Uglifying File 851 of 888 - jquery/src/intro
Whatever javascript file that is mentioned there probably has either some syntax error, or possibly weird non-ascii characters that were introduced because of file encoding issues or something.

How do I get Unicorn to show post parameters in the development log?

I just started giving Unicorn a try (over Thin), and so far I do like the format of the output, except that it doesn't appear to show the post parameters for various requests. I really like this functionality to help debug forms etc....
Unicorn:
20:26:14 web.1 | 127.0.0.1 - - [17/Jan/2012 20:26:14] "POST /basic_simulations HTTP/1.1" 422 24259 0.4838
What I want... (this is from webrick):
Started POST "/basic_simulations" for 127.0.0.1 at 2012-01-17 20:27:22 -0700
Processing by BasicSimulationsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"xxxxx", "basic_simulation"=>{"x1706"=>"1"}, "commit"=>"Submit my answers"}
Is there some config option or something of the sort where I can turn this functionality on? Thanks!
UPDATE:
Add this to your config/application.rb file:
config.logger = Logger.new(STDOUT)
More info here
Add this to your config/environments/development.rb file:
config.logger = Logger.new(STDOUT)
More info here
Try this in your site configuration:
log_format postdata $request_body;
access_log /var/log/nginx/postdata.log postdata;
More informations here: Logging POST data from $request_body
If you're using Foreman with a procfile, you can add this line to your Procfile:
devlog: tail -f log/development.log
and it will put the development log to terminal window like webrick.

TZInfo::InvalidTimezoneIdentifier with rails 3.1.0 and ubuntu

Here is the error in log file when making initial http connection to the server. It is odd that sometime the server can render a http connection without any problem. But more often with the TZinfo error.
Started GET "/" for 98.206.231.173 at 2011-11-13 09:41:34 +0800
Processing by SessionsController#new as HTML
Rendered sessions/new.html.erb within layouts/sessions (2.2ms)
Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.0ms)
TZInfo::InvalidTimezoneIdentifier (no such file to load -- tzinfo/definitions/Etc/UTC):
Any suggestion to fix it? Thanks.
how do you serve your Rails application? Mongrel? Unicorn? ...? can you restart your app, to make sure that all threads have the same config?
Do you have 'tzinfo' listed as a dependency in your Gemfile?
Which version of TZinfo are you using? Can you try to update TZInfo to the latest version?
e.g. run bundle update
all the newer versions of TZInfo, like 0.3.30 , have the directory lib/tzinfo/definitions/Etc with the UTC.rb definition in it as follows:
$ more .rvm/gems/ruby-1.9.2-p0/gems/tzinfo-0.3.30/lib/tzinfo/definitions/Etc/UTC.rb
module TZInfo
module Definitions
module Etc
module UTC
include TimezoneDefinition
timezone 'Etc/UTC' do |tz|
tz.offset :o0, 0, 0, :UTC
end
end
end
end
end
What do you see underneath your .rvm/gems/RUBY-VERSION/gems/ directory? which TZInfo are you using? and is the UTC.rb file there? Are the permissions on the directory and the file 'world readable'?
Maybe it's related to this:
http://rubyglasses.blogspot.com/2008/05/converting-timezone-to-tzinfotimezone.html

Rails 3.1 rake test:profile deprecation warning and empty output files

When runnign rake test:profile I get:
DEPRECATION WARNING: read_csv_fixture_files is deprecated and will be
removed from Rails 3.2. (called from block in autorun at
/Users/hade/.rvm/rubies/ruby-1.9.2-p290-perf/lib/ruby/1.9.1/minitest/unit.rb:508)
Unit.rb around line 508:
def self.autorun
at_exit {
next if $! # don't run if there was an exception
# the order here is important. The at_exit handler must be
# installed before anyone else gets a chance to install their
# own, that way we can be assured that our exit will be last
# to run (at_exit stacks).
exit_code = nil
at_exit { exit false if exit_code && exit_code != 0 }
exit_code = MiniTest::Unit.new.run(ARGV) <------ LINE 508
} unless ##installed_at_exit
##installed_at_exit = true
end
Is MiniTest calling this read_csv_fixture_files method? Is this normal behaviour with my setup? How can I remove this?
My environment:
Rails 3.1.0
Ruby 1.9.2-p290 with GC-patch
My tests seem to run ok, but my output files are useless. In my output files I only have this line:
ActiveSupport::Testing::Performance::Profiler#run
But when I run rails profiler 'User.all' I get nice console output and output files with some content.
Any help would be really appreciated. I have tried different Ruby versions with GC-patch, but no help there.

Heroku: see params and sql activity in logs?

When i view my heroku logs on the server (with heroku logs --tail --app myapp) i see something like this:
2011-06-21T14:09:25+00:00 app[web.1]: Started PUT "/reports/19.xml" for 77.89.149.137 at 2011-06-21 07:09:25 -0700
2011-06-21T14:09:25+00:00 heroku[router]: PUT myapp.heroku.com/reports/19.xml dyno=web.1 queue=0 wait=0ms service=7ms status=401 bytes=28
2011-06-21T14:09:26+00:00 heroku[nginx]: PUT /reports/19.xml HTTP/1.1 | 77.89.149.137 | 656 | http | 401
While in my local log i'd see something like this:
Started PUT "/reports/19" for 127.0.0.1 at 2011-06-21 15:27:01 +0100
Processing by ReportsController#update as XML
Parameters: {"report"=>{"workflow_status"=>"3"}, "id"=>"19"}
Person Load (0.9ms) SELECT "people".* FROM "people" WHERE "people"."email" = 'madeupemai#lkklj.com' LIMIT 1
Report Load (0.4ms) SELECT "reports".* FROM "reports" WHERE "reports"."id" = 19 LIMIT 1
DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from update_report at /home/max/work/rails_apps/flamingo_container/flamingo/vendor/plugins/resource_this/lib/resource_this.rb:135)
Creating scope :open. Overwriting existing method Task.open.
Task Load (2.0ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = 14 LIMIT 1
Completed 200 OK in 1648ms (Views: 568.2ms | ActiveRecord: 3.2ms)
Ie with a lot more information, particularly the params, info from the router, generated sql, any templates rendered etc etc.
Does anyone know how i can get my heroku log to be as verbose as my development one? I've done the following already:
1) Set the log level in the relevant (rails 3) environment file:
config.log_level = :debug
2) Told heroku to use a different logger level, as described on http://devcenter.heroku.com/articles/logging
heroku config:add LOG_LEVEL=DEBUG --app myapp #from CLI
Neither has made any difference...any ideas anyone?
thanks, max
You're essentially wanting to show the SQL / params output in the Heroku logs. You can do this by adding the line shown below to the config block within your production.rb file:
MyAppNameHere::Application.configure do
# add this line
config.logger = Logger.new(STDOUT)
end
By the way, setting the log level to debug just means that Rails.logger.debug will output to the logs when you're on Heroku
In your production.rb add config.log_level = :debug and redeploy. That will give you the same logs as development mode :)
The detailed log you want is generated by the function start_processing in log_subscriber.rb.
action_controller/log_subscriber.rb:
def start_processing(event)
payload = event.payload
params = payload[:params].except(*INTERNAL_PARAMS)
info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
info " Parameters: #{params.inspect}" unless params.empty?
end
I checked with rails 3.0.4 in development and production environment. In both environments, we have the detailed logs.
This is an info level log. That's why the debug log level is not changing the output.
I installed the plugin used by heroku rails_log_stdout (Heroku logging) but I still have the desired output.
Right now, I can't test with heroku to find out why you don't have all the logs.
In the heroku example (see Heroku logging, section log retrieval), we don't see the "Processing" and "Parameters" lines. I think that either this method is not called when the app is running on heroku (it is somehow disabled) or heroku skips logs starting with whitespaces. Could you try to log messages starting with whitespaces and see if heroku is showing them?
Rails doesn't generate those logs when in production mode. http://groups.google.com/group/heroku/browse_thread/thread/d778fafedc9a378a
The real problem is actually due to the way Heroku works in conjunction with rails. The right way to solve this is to add: gem 'rails_12factor', group: :production
See https://devcenter.heroku.com/articles/rails-integration-gems for more info on the matter
Looks like the puma server doesn't play well with Heroku. In my project, I tried everything, but it still wouldn't log. I then replaced Puma with Unicorn, and bam, full logs are being shown.

Resources