Class: Gruf::Interceptors::Instrumentation::RequestLogging::Formatters::Plain

Inherits:
Base
  • Object
show all
Defined in:
lib/gruf/interceptors/instrumentation/request_logging/formatters/plain.rb

Overview

Formats the request into plaintext logging

Instance Method Summary collapse

Instance Method Details

#format(payload) ⇒ String

Format the request by only outputting the message body and params (if set to log params)

Parameters:

  • payload (Hash)

    The incoming request payload

Returns:

  • (String)

    The formatted string



31
32
33
34
35
36
37
38
39
40
# File 'lib/gruf/interceptors/instrumentation/request_logging/formatters/plain.rb', line 31

def format(payload)
  time = payload.fetch(:duration, 0)
  grpc_status = payload.fetch(:grpc_status, 'GRPC::Ok')
  route_key = payload.fetch(:method, 'unknown')
  body = payload.fetch(:message, '')

  msg = "[#{grpc_status}] (#{route_key}) [#{time}ms] #{body}".strip
  msg += " Parameters: #{payload[:params].to_h}" if payload.key?(:params)
  msg.strip
end