lib/contrast/logger/time.rb in contrast-agent-6.6.0 vs lib/contrast/logger/time.rb in contrast-agent-6.6.1
- old
+ new
@@ -6,34 +6,41 @@
# Our decorator for the Ougai logger allowing for timing and with_level
# methods.
module Time
# Log the message at the given level.
#
- # @param level [String] the name of the method to use. Should be one of
- # trace, debug, info, warn, error
+ # @param level [String] the name of the method to use. Should be one of trace, debug, info, warn, error
# @param message [String] the message to log
def with_level level, message
send(level.to_sym, message)
end
- # Log, at the debug level, the action with a message including the time
- # it took for the wrapped function to complete.
+ # 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.
#
- # @param msgs [Array<Object>] the arguments to pass to the logger.
- # msgs[0] will be modified to include the elapsed time.
+ # @param msgs [Array<Object>] the arguments to pass to the logger. msgs[0] will be modified to include the elapsed
+ # time.
# @param block [Block, Proc] the block to execute
def debug_with_time *msgs, &block
- log_with_time(:debug, *msgs, &block)
+ if debug?
+ log_with_time(:debug, *msgs, &block)
+ elsif block
+ yield
+ end
end
- # Log, at the trace level, the action with a message including the time
- # it took for the wrapped function to complete.
+ # 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.
#
- # @param msgs [Array<Object>] the arguments to pass to the logger.
- # msgs[0] will be modified to include the elapsed time.
+ # @param msgs [Array<Object>] the arguments to pass to the logger. msgs[0] will be modified to include the elapsed
+ # time.
# @param block [Block, Proc] the block to execute
def trace_with_time *msgs, &block
- log_with_time(:trace, *msgs, &block)
+ if trace?
+ log_with_time(:trace, *msgs, &block)
+ elsif block
+ yield
+ end
end
private
def log_with_time level, *msgs