Class: Bones::RPC::Instrumentable::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/bones/rpc/instrumentable/log.rb

Overview

Provides logging instrumentation for compatibility with active support notifications.

Since:

  • 2.0.0

Class Method Summary collapse

Class Method Details

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

Instrument the log payload.

Examples:

Instrument the log payload.

Log.instrument("bones-rpc.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


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bones/rpc/instrumentable/log.rb', line 25

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)))
    if name == TOPIC
      Bones::RPC::Loggable.log_operations(payload[:prefix], payload[:ops], runtime)
    else
      Bones::RPC::Loggable.debug(payload[:prefix], payload.reject { |k,v| k == :prefix }, runtime)
    end
  end
end