Class: RuboCop::Cop::Mdsol::LogWithData
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Mdsol::LogWithData
- Defined in:
- lib/rubocop/cop/mdsol/log_with_data.rb
Overview
Favor the logger.<level>_with_data method for structured logging.
Constant Summary collapse
- MSG =
"Use `logger.%<method>s_with_data(msg, data_hash)` instead. See https://github.com/mdsol/astinus#using-context-data-logging"
- RESTRICT_ON_SEND =
%i[logger debug info warn error].freeze
- FORBIDDEN_ENUMERABLE_METHODS =
%i[map collect].freeze
- DEFAULT_STRING_INTERPOLATION_THRESHOLD =
2
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubocop/cop/mdsol/log_with_data.rb', line 48 def on_send(node) logger_with_interpolation(node) do |logger_owner, log_method, | return unless registered_logger_owners.include?(logger_owner.to_s) if interpoloations_exceed_threshold?() || contain_forbidden_enumerable_method?() msg = format(MSG, method: log_method.to_s) add_offense(node, message: msg) end end end |