Module: Contrast::Logger::Time

Defined in:
lib/contrast/logger/time.rb

Overview

Our decorator for the Ougai logger allowing for timing and with_level methods.

Instance Method Summary collapse

Instance Method Details

#debug_with_time(*msgs, &block) ⇒ Object

Log, at the debug level, the action with a message including the time it took for the wrapped function to complete. If not logging to debug, simply yield the given block.

Parameters:

  • msgs (Array<Object>)

    the arguments to pass to the logger. msgs will be modified to include the elapsed time.

  • block (Block, Proc)

    the block to execute



23
24
25
26
27
28
29
# File 'lib/contrast/logger/time.rb', line 23

def debug_with_time *msgs, &block
  if debug?
    log_with_time(:debug, *msgs, &block)
  elsif block
    yield
  end
end

#trace_with_time(*msgs, &block) ⇒ Object

Log, at the trace level, the action with a message including the time it took for the wrapped function to complete. If not logging to debug, simply yield the given block.

Parameters:

  • msgs (Array<Object>)

    the arguments to pass to the logger. msgs will be modified to include the elapsed time.

  • block (Block, Proc)

    the block to execute



37
38
39
40
41
42
43
# File 'lib/contrast/logger/time.rb', line 37

def trace_with_time *msgs, &block
  if trace?
    log_with_time(:trace, *msgs, &block)
  elsif block
    yield
  end
end

#with_level(level, message) ⇒ Object

Log the message at the given level.

Parameters:

  • level (String)

    the name of the method to use. Should be one of trace, debug, info, warn, error

  • message (String)

    the message to log



13
14
15
# File 'lib/contrast/logger/time.rb', line 13

def with_level level, message
  send(level.to_sym, message)
end