Module: DebugLogging::InstanceLogger

Defined in:
lib/debug_logging/instance_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
# File 'lib/debug_logging/instance_logger.rb', line 4

def extended(base)
  base.include(LambDartable::Log)
end

Instance Method Details

#i_logged(*methods_to_log) ⇒ Object

NOTE: These params can be passed in / hidden in a last hash of *args NOTE: They can also be passed in discretely for each method, by passing *args as an array of arrays TODO: Refactor to use modern Ruby 3 *args, **kwargs instead

Parameters:

  • logger (Logger)

    Logger.new($stdout), # probably want to override to be the Rails.logger

  • log_level (Symbol)

    default: :debug, at what level do the messages created by this gem sent at?

  • multiple_last_hashes (true, false)

    default: false,

  • last_hash_to_s_proc (nil, Proc)

    default: nil, e.g. ->(hash) { “keys: #DebugLogging::InstanceLogger.hashhash.keys” }

  • last_hash_max_length (Integer)

    default: 1_000,

  • args_to_s_proc (nil, Proc)

    default: nil, e.g. ->(*record) { “record id: #DebugLogging::InstanceLogger.recordrecord.firstrecord.first.id” }

  • args_max_length (Integer)

    default: 1_000,

  • colorized_chain_for_method (false, Proc)

    default: false, e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }

  • colorized_chain_for_class (false, Proc)

    default: false, e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }

  • add_invocation_id (true, false)

    default: true, allows unique identification of method call; association of entry and exit log lines

  • ellipsis (String)

    default: “ ✂️ …”.freeze,

  • mark_scope_exit (true, false)

    default: false,

  • add_payload (true, false, Proc)

    default: true, # Can also be a proc returning a string, which will be called when printing the payload

  • payload_max_length (Integer)

    default: 1_000,

  • error_handler_proc (nil, Proc)

    default: nil,

  • time_formatter_proc (nil, Proc)

    default: DebugLogging::Constants::DEFAULT_TIME_FORMATTER,

  • add_timestamp (true, false)

    default: false,

  • instance_benchmarks (true, false)

    default: false,

  • class_benchmarks (true, false)

    default: false,



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/debug_logging/instance_logger.rb', line 31

def i_logged(*methods_to_log)
  methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
    method_names: methods_to_log,
    payload: nil,
    config: nil,
  )
  instance_method_modules =
    Array(methods_to_log).map do |decorated_method|
      DebugLogging::InstanceLoggerModulizer.to_mod(
        methods_to_log: Array(decorated_method),
        payload: payload,
        config: config_opts,
      )
    end
  wrapped_in_logs = Module.new do
    singleton_class.send(:define_method, :included) do |host_class|
      instance_method_modules.each do |mod|
        host_class.prepend(mod)
      end
    end
  end

  send(:include, wrapped_in_logs)
end