Module: TrackerHub::Request::Format::Logger

Included in:
TrackerHub::Request
Defined in:
lib/tracker_hub/request/format/logger.rb

Overview

Logger module formatting and rendering the request object

Instance Method Summary collapse

Instance Method Details

#cleaned_envUtils::Env

Extract the rack env keys (see TrackerHub::Request::Config#required_keys)

and convert them

Examples:

> status, headers, body = @app.call(env)
> track = TrackerHub::Request.new(env, status, headers)
> track.cleaned_env

Returns:



37
38
39
# File 'lib/tracker_hub/request/format/logger.rb', line 37

def cleaned_env
  response.slice(*Request.config.required_keys).merge(serialized_env)
end

#serialized_envHash

Serialize objects before jsonifying them

rubocop:disable AbcSize

Examples:

> status, headers, body = @app.call(env)
> track = TrackerHub::Request.new(env, status, headers)
> track.serialized_env

Returns:

  • (Hash)


53
54
55
56
57
58
59
60
61
# File 'lib/tracker_hub/request/format/logger.rb', line 53

def serialized_env
  {
    'action_dispatch.logger' => response['action_dispatch.logger'].formatter.session_info,
    'action_dispatch.remote_ip'   => response['action_dispatch.remote_ip'].to_s,
    'rack.session'                => response['rack.session'].try(:to_hash),
    'rack.session.options'        => response['rack.session.options'].try(:to_hash),
    'http_accept_language.parser' => response['http_accept_language.parser'].header
  }
end

#to_loggerJSON

Format the response to the logger

Examples:

> status, headers, body = @app.call(env)
> track = TrackerHub::Request.new(env, status, headers)
> track.to_logger

Returns:

  • (JSON)


16
17
18
19
20
21
22
23
24
# File 'lib/tracker_hub/request/format/logger.rb', line 16

def to_logger
  {
    status:          status,
    request:         request,
    response:        cleaned_env,
    app_version:     Request.config.app_version,
    tracker_version: Request::VERSION
  }.to_json
end