Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Web log spam #365

Closed
alias1 opened this Issue · 5 comments

3 participants

@alias1
Collaborator

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)
@cantino
Owner
@alias1
Collaborator

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?

@dsander
Collaborator

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

@cantino
Owner

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.

@alias1
Collaborator

Closing because of #389

@alias1 alias1 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.