Module: RedisQueuedLocks::Logging
- Defined in:
- lib/redis_queued_locks/logging.rb
Overview
Defined Under Namespace
Modules: Sampler, VoidLogger
Class Method Summary collapse
- .should_log?(log_sampling_enabled, log_sample_this, log_sampling_percent, log_sampler) ⇒ Boolean private
- .valid_interface?(logger) ⇒ Boolean
- .valid_sampler?(sampler) ⇒ Boolean private
Class Method Details
.should_log?(log_sampling_enabled, log_sample_this, log_sampling_percent, log_sampler) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/redis_queued_locks/logging.rb', line 19 def should_log?( log_sampling_enabled, log_sample_this, log_sampling_percent, log_sampler ) return true unless log_sampling_enabled return true if log_sample_this log_sampler.sampling_happened?(log_sampling_percent) end |
.valid_interface?(logger) ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/redis_queued_locks/logging.rb', line 69 def valid_interface?(logger) return true if logger.is_a?(::Logger) # NOTE: # - convinient/conventional way to support the popular `semantic_logger` library # - see https://logger.rocketjob.io/ # - see https://github.com/reidmorrison/semantic_logger # - convinient/conventional way to support the popular `broadcast` RubyOnRails's logger; # - see https://api.rubyonrails.org/classes/ActiveSupport/BroadcastLogger.html return true if defined?(::SemanticLogger::Logger) && logger.is_a?(::SemanticLogger::Logger) return true if defined?(::ActiveSupport::BroadcastLogger) && logger.is_a?(::ActiveSupport::BroadcastLogger) # NOTE: should provide `#debug` method. return false unless logger.respond_to?(:debug) # NOTE: # `#debug` method should have appropriated signature `(progname, &block)` # Required method signature (progname, &block): # => [[:opt, :progname], [:block, :block]] # => [[:req, :progname], [:block, :block]] # => [[:opt, :progname]] # => [[:req, :progname]] # => [[:rest], [:block, :block]] # => [[:rest]] # => ((...) method signature): [[:rest, :*], [:keyrest, :**], [:block, :&]] # @type var m_obj: Method m_obj = logger.method(:debug) m_sig = m_obj.parameters case m_sig.size when 2 # => [[:opt, :progname], [:block, :block]] # => [[:req, :progname], [:block, :block]] # => [[:rest], [:block, :block]] f_prm = m_sig[0][0] s_prm = m_sig[1][0] # rubocop:disable Layout/MultilineOperationIndentation f_prm == :opt && s_prm == :block || f_prm == :req && s_prm == :block || f_prm == :rest && s_prm == :block # rubocop:enable Layout/MultilineOperationIndentation when 1 # => [[:opt, :progname]] # => [[:req, :progname]] # => [[:rest]] prm = m_sig[0][0] prm == :opt || prm == :req || prm == :rest when 3 # => [[:rest, :*], [:keyrest, :**], [:block, :&]] f_prm = m_sig[0][0] s_prm = m_sig[1][0] t_prm = m_sig[2][0] f_prm == :rest && s_prm == :keyrest && t_prm == :block else false end end |
.valid_sampler?(sampler) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/redis_queued_locks/logging.rb', line 35 def valid_sampler?(sampler) return false unless sampler.respond_to?(:sampling_happened?) m_obj = sampler.method(:sampling_happened?) m_sig = m_obj.parameters # NOTE: # Required method signature (sampling_percent) # => [[:req, :sampling_percent]] # => [[:opt, :sampling_percent]] # => [[:req, :sampling_percent], [:block, :block]] # => [[:opt, :sampling_percent], [:block, :block]] if m_sig.size == 1 prm = m_sig[0][0] prm == :req || prm == :opt elsif m_sig.size == 2 f_prm = m_sig[0][0] s_prm = m_sig[1][0] # rubocop:disable Layout/MultilineOperationIndentation f_prm == :req && s_prm == :block || f_prm == :opt && s_prm == :block # rubocop:enable Layout/MultilineOperationIndentation else false end end |