Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Web log spam #365

Closed
0xdevalias opened this Issue Jun 2, 2014 · 5 comments

Comments

Projects
None yet
3 participants
Member

0xdevalias commented Jun 2, 2014

I was wondering if there was any easy/nice way of preventing the web log spam (at least on my dev instance) from /worker_status?

20:46:11 web.1      | Started GET "/worker_status" for 127.0.0.1 at 2014-06-02 20:46:11 +1000
20:46:11 web.1      | Processing by WorkerStatusController#show as JSON
20:46:11 web.1      | Geokit is using the domain: 
20:46:11 web.1      |   User Load (0.4ms)  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
20:46:11 web.1      |    (0.2ms)  SELECT COUNT(*) FROM `delayed_jobs`  WHERE (run_at <= '2014-06-02 10:46:11' AND locked_at IS NULL AND attempts = 0)
20:46:11 web.1      |    (0.2ms)  SELECT COUNT(*) FROM `delayed_jobs`  WHERE (failed_at IS NULL AND attempts > 0)
20:46:11 web.1      |    (0.2ms)  SELECT COUNT(*) FROM `delayed_jobs`  WHERE (failed_at IS NOT NULL AND failed_at > '2014-05-28 10:46:11')
20:46:11 web.1      |    (0.3ms)  SELECT COUNT(*) FROM `events`  WHERE `events`.`user_id` = 1
20:46:11 web.1      | Completed 200 OK in 5ms (Views: 0.1ms | ActiveRecord: 1.2ms)
Owner

cantino commented Jun 2, 2014

Yea, that'd be nice. We might be able to move it to a rack handler? Or
maybe you can Google and see if there's a way to skip certain logs in rails?

On Monday, June 2, 2014, alias1 notifications@github.com wrote:

I was wondering if there was any easy/nice way of preventing the web log
spam (at least on my dev instance) from /worker_status?

20:46:11 web.1 | Started GET "/worker_status" for 127.0.0.1 at 2014-06-02 20:46:11 +1000
20:46:11 web.1 | Processing by WorkerStatusController#show as JSON
20:46:11 web.1 | Geokit is using the domain:
20:46:11 web.1 | User Load (0.4ms) SELECT users.* FROM users WHERE users.id = 1 ORDER BY users.id ASC LIMIT 1
20:46:11 web.1 | (0.2ms) SELECT COUNT() FROM delayed_jobs WHERE (run_at <= '2014-06-02 10:46:11' AND locked_at IS NULL AND attempts = 0)
20:46:11 web.1 | (0.2ms) SELECT COUNT(
) FROM delayed_jobs WHERE (failed_at IS NULL AND attempts > 0)
20:46:11 web.1 | (0.2ms) SELECT COUNT() FROM delayed_jobs WHERE (failed_at IS NOT NULL AND failed_at > '2014-05-28 10:46:11')
20:46:11 web.1 | (0.3ms) SELECT COUNT(
) FROM events WHERE events.user_id = 1
20:46:11 web.1 | Completed 200 OK in 5ms (Views: 0.1ms | ActiveRecord: 1.2ms)


Reply to this email directly or view it on GitHub
cantino#365.

Member

0xdevalias commented Jun 3, 2014

It sounds like this one (for assets) uses a Rack sort of thing: https://github.com/evrone/quiet_assets/blob/master/lib/quiet_assets.rb


http://stackoverflow.com/questions/7365630/how-to-ignore-rails-3-assets-from-log

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 

Does that sound like the right sort of thing to you?

Collaborator

dsander commented Jun 3, 2014

I also do not know of a build in way to silence logging for just one method. Thats what we are using in a different project:

quiet_logger.rb

module Utils
  class QuietLogger < Rails::Rack::Logger
    def initialize(app, opts = {})
      @app = app
      @opts = opts
      super
    end

    def call(env)
      begin
        route = Rails.application.routes.recognize_path(env['PATH_INFO'], method: env['REQUEST_METHOD'].downcase.to_sym)
      rescue
        return super(env)
      end

      action = route[:action]
      controller = route[:controller]
      controller_klass = (controller.split('/').map { |p| p.camelize }.join('::') + 'Controller').constantize

      if controller_klass.class_variable_defined?(:@@silenced_actions) &&
        controller_klass.class_variable_get(:@@silenced_actions).include?(action.to_sym)
        log_only_errors do
          @app.call(env)
        end
      else
        super(env)
      end
    end

    def log_only_errors
      old_level = Rails.logger.level
      Rails.logger.level = Logger::ERROR
      r = yield
      Rails.logger.level = old_level
      r
    end
  end
end

initializer

Huginn::Application.config.middleware.swap Rails::Rack::Logger, Utils::QuietLogger

controller

  @@silenced_actions = [:updates]

But I am not sure if this works in rails 4

Owner

cantino commented Jun 4, 2014

Both approaches seem reasonable. The quiet_assets approach, if it works, might be a bit better since it doesn't seem to patch how all logging works.

Member

0xdevalias commented Jul 30, 2014

Closing because of #389

@0xdevalias 0xdevalias closed this Jul 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment