Class: SmartLoggerWrapper::Options::WithPosition

Inherits:
Base
  • Object
show all
Includes:
Utils::Backtrace, Utils::Path
Defined in:
lib/smart_logger_wrapper/options/with_position.rb

Constant Summary

Constants included from Utils::Path

Utils::Path::DIR_TRIMMER_PATTERN

Instance Method Summary collapse

Methods included from Utils::Backtrace

clean_backtrace, get_backtrace

Methods included from Utils::Path

trim_dirname

Instance Method Details

#apply!(messages, arguments, severity, wrapper) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smart_logger_wrapper/options/with_position.rb', line 12

def apply!(messages, arguments, severity, wrapper)
  enabled = arguments.first || true
  return unless enabled
  # add 1 to `start` because this method dug the backtrace by 1
  location = caller_locations(wrapper.offset + APPLY_CALLER_STACK_DEPTH + 1, 1)
  prefix =
    if location && location.length > 0 && location_important?(location)
      method_name = location[0].label
      path        = trim_dirname(location[0].absolute_path)
      lineno      = location[0].lineno
      "[#{method_name}@#{path}:#{lineno}]"
    else
      nil
    end
  messages.map! { |message| [prefix, message].compact.join(' ') }
end