Class: TwirpRails::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/twirp_rails/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#default_log_writer(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/twirp_rails/log_subscriber.rb', line 13

def default_log_writer(event)
  twirp_call_info = {
    'duration' => event.duration,
    'method' => event.payload[:env][:rpc_method],
    'params' => event.payload[:env][:input].to_h
  }

  if (exception = event.payload[:env][:exception])
    twirp_call_info['exception'] = exception
  end

  Rails.logger.info twirp_call_info
end

#instrumenter(event) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/twirp_rails/log_subscriber.rb', line 5

def instrumenter(event)
  if LogSubscriber.log_writer
    LogSubscriber.log_writer.call(event)
  else
    default_log_writer(event)
  end
end