Sha256: 252f13e02c4ae05b2206a3abc5f2714fa2b2d414adac3ecf62bb304873a21fa7

Contents?: true

Size: 1.2 KB

Versions: 121

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
if ENV["PROFILE_BAD_LOG_CALLS"] || ($DEBUGLIST || []).include?("log")
  # Set PROFILE_BAD_LOG_CALLS=1 in your environment if you want
  # to track down logger calls that cause performance problems
  #
  # Related research here:
  #   https://github.com/jordansissel/experiments/tree/master/ruby/logger-string-vs-block
  #
  # Basically, the following is wastes tons of effort creating objects that are
  # never used if the log level hides the log:
  #
  #     logger.debug("something happend", :what => Happened)
  #
  # This is shown to be 4x faster:
  #
  #     logger.debug(...) if logger.debug?
  #
  # I originally intended to use RubyParser and SexpProcessor to
  # process all the logstash ruby code offline, but it was much
  # faster to write this monkeypatch to warn as things are called.
  require "cabin/mixins/logger"
  module Cabin::Mixins::Logger
    LEVELS.keys.each do |level|
      m = "original_#{level}".to_sym
      predicate = "#{level}?".to_sym
      alias_method m, level
      define_method(level) do |*args|
        if !send(predicate)
          warn("Unconditional log call", :location => caller[0])
        end
        send(m, *args)
      end
    end
  end
end # PROFILE_BAD_LOG_CALLS

Version data entries

121 entries across 114 versions & 12 rubygems

Version Path
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/logstash-core-5.0.0-java/lib/logstash/patches/cabin.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
logstash-core-5.3.3-java lib/logstash/patches/cabin.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/logstash-core-5.2.1-java/lib/logstash/patches/cabin.rb
logstash-core-5.3.2-java lib/logstash/patches/cabin.rb
logstash-core-5.3.1-java lib/logstash/patches/cabin.rb
logstash-core-5.3.0-java lib/logstash/patches/cabin.rb
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/logstash-core-2.4.1-java/lib/logstash/patches/cabin.rb
logstash-core-5.2.2-java lib/logstash/patches/cabin.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/logstash-core-2.4.1-java/lib/logstash/patches/cabin.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/logstash-core-5.1.1.1-java/lib/logstash/patches/cabin.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/logstash-core-5.1.1.1-java/lib/logstash/patches/cabin.rb
logstash-core-5.2.1-java lib/logstash/patches/cabin.rb
logstash-core-5.2.0-java lib/logstash/patches/cabin.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/logstash-core-5.1.1.1-java/lib/logstash/patches/cabin.rb
logstash-core-5.1.2-java lib/logstash/patches/cabin.rb