Module: Moped::Instrumentable::Log

Extended by:
Log
Included in:
Log
Defined in:
lib/moped/instrumentable/log.rb

Overview

Provides logging instrumentation for compatibility with active support notifications.

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#instrument(name, payload = {}) ⇒ Object

Instrument the log payload.

Examples:

Instrument the log payload.

Log.instrument("moped.ops", {})

Parameters:

  • name (String)

    The name of the logging type.

  • payload (Hash) (defaults to: {})

    The log payload.

Returns:

  • (Object)

    The result of the yield.

Since:

  • 2.0.0



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/moped/instrumentable/log.rb', line 23

def instrument(name, payload = {})
  started = Time.new
  begin
    yield if block_given?
  rescue Exception => e
    payload[:exception] = [ e.class.name, e.message ]
    raise e
  ensure
    runtime = ("%.4fms" % (1000 * (Time.now.to_f - started.to_f)))
    Moped::Loggable.log_operations(payload[:prefix], payload[:ops], runtime)
  end
end