Class: LogStruct::Log::Request

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Includes:
Interfaces::AdditionalDataField, Interfaces::CommonFields, Interfaces::RequestFields, Shared::AddRequestFields, Shared::MergeAdditionalDataFields, Shared::SerializeCommon
Defined in:
lib/log_struct/log/request.rb

Constant Summary

Constants included from Shared::MergeAdditionalDataFields

Shared::MergeAdditionalDataFields::RESERVED_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shared::AddRequestFields

#add_request_fields

Methods included from Shared::SerializeCommon

#as_json, #serialize, #serialize_common

Methods included from Interfaces::CommonFieldBase

#serialize

Methods included from Shared::MergeAdditionalDataFields

#merge_additional_data_fields

Constructor Details

#initialize(source: Source::Rails, event: Event::Request, timestamp:, level: Level::Info, path: nil, http_method: nil, source_ip: nil, user_agent: nil, referer: nil, format: nil, controller: nil, action: nil, status: nil, duration_ms: nil, view: nil, database: nil, params: nil, host: nil, content_type: nil, accept: nil, additional_data: nil) ⇒ void

Parameters:

  • source (Source::Rails) (defaults to: Source::Rails)

    Shared/common fields

  • event (Event) (defaults to: Event::Request)
  • timestamp (Time)
  • level (Level) (defaults to: Level::Info)
  • path (String, nil) (defaults to: nil)
  • http_method (String, nil) (defaults to: nil)
  • source_ip (String, nil) (defaults to: nil)
  • user_agent (String, nil) (defaults to: nil)
  • referer (String, nil) (defaults to: nil)
  • format (Symbol, nil) (defaults to: nil)

    Event-specific fields

  • controller (String, nil) (defaults to: nil)
  • action (String, nil) (defaults to: nil)
  • status (Integer, nil) (defaults to: nil)
  • duration_ms (Float, nil) (defaults to: nil)
  • view (Float, nil) (defaults to: nil)
  • database (Float, nil) (defaults to: nil)
  • params (Hash{Symbol => T.untyped}, nil) (defaults to: nil)
  • host (String, nil) (defaults to: nil)
  • content_type (String, nil) (defaults to: nil)
  • accept (String, nil) (defaults to: nil)
  • additional_data (Hash{String, Symbol => T.untyped}, nil) (defaults to: nil)


# File ''

const :source, Source::Rails, default: Source::Rails
const :event, Event, default: Event::Request
const :timestamp, Time, factory: -> { Time.now }
const :level, Level, default: Level::Info
const :path, T.nilable(String), default: nil
const :http_method, T.nilable(String), default: nil
const :source_ip, T.nilable(String), default: nil
const :user_agent, T.nilable(String), default: nil
const :referer, T.nilable(String), default: nil
const :format, T.nilable(Symbol), default: nil
const :controller, T.nilable(String), default: nil
const :action, T.nilable(String), default: nil
const :status, T.nilable(Integer), default: nil
const :duration_ms, T.nilable(Float), default: nil
const :view, T.nilable(Float), default: nil
const :database, T.nilable(Float), default: nil
const :params, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
const :host, T.nilable(String), default: nil
const :content_type, T.nilable(String), default: nil
const :accept, T.nilable(String), default: nil
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil

Instance Attribute Details

#acceptString? (readonly)

Returns the value of prop accept.

Returns:

  • (String, nil)


# File ''

const :accept, T.nilable(String), default: nil

#actionString? (readonly)

Returns the value of prop action.

Returns:

  • (String, nil)


# File ''

const :action, T.nilable(String), default: nil

#additional_dataHash{String, Symbol => T.untyped}? (readonly)

Returns the value of prop additional_data.

Returns:

  • (Hash{String, Symbol => T.untyped}, nil)


# File ''

const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil

#content_typeString? (readonly)

Returns the value of prop content_type.

Returns:

  • (String, nil)


# File ''

const :content_type, T.nilable(String), default: nil

#controllerString? (readonly)

Returns the value of prop controller.

Returns:

  • (String, nil)


# File ''

const :controller, T.nilable(String), default: nil

#databaseFloat? (readonly)

Returns the value of prop database.

Returns:

  • (Float, nil)


# File ''

const :database, T.nilable(Float), default: nil

#duration_msFloat? (readonly)

Returns the value of prop duration_ms.

Returns:

  • (Float, nil)


# File ''

const :duration_ms, T.nilable(Float), default: nil

#eventEvent (readonly)

Returns the value of prop event.

Returns:



# File ''

const :event, Event, default: Event::Request

#formatSymbol? (readonly)

Event-specific fields

Returns:

  • (Symbol, nil)


# File ''

const :format, T.nilable(Symbol), default: nil

#hostString? (readonly)

Returns the value of prop host.

Returns:

  • (String, nil)


# File ''

const :host, T.nilable(String), default: nil

#http_methodString? (readonly)

Returns the value of prop http_method.

Returns:

  • (String, nil)


# File ''

const :http_method, T.nilable(String), default: nil

#levelLevel (readonly)

Returns the value of prop level.

Returns:



# File ''

const :level, Level, default: Level::Info

#paramsHash{Symbol => T.untyped}? (readonly)

Returns the value of prop params.

Returns:

  • (Hash{Symbol => T.untyped}, nil)


# File ''

const :params, T.nilable(T::Hash[Symbol, T.untyped]), default: nil

#pathString? (readonly)

Returns the value of prop path.

Returns:

  • (String, nil)


# File ''

const :path, T.nilable(String), default: nil

#refererString? (readonly)

Returns the value of prop referer.

Returns:

  • (String, nil)


# File ''

const :referer, T.nilable(String), default: nil

#sourceSource::Rails (readonly)

Shared/common fields

Returns:



# File ''

const :source, Source::Rails, default: Source::Rails

#source_ipString? (readonly)

Returns the value of prop source_ip.

Returns:

  • (String, nil)


# File ''

const :source_ip, T.nilable(String), default: nil

#statusInteger? (readonly)

Returns the value of prop status.

Returns:

  • (Integer, nil)


# File ''

const :status, T.nilable(Integer), default: nil

#timestampTime (readonly)

Returns the value of prop timestamp.

Returns:

  • (Time)


# File ''

const :timestamp, Time, factory: -> { Time.now }

#user_agentString? (readonly)

Returns the value of prop user_agent.

Returns:

  • (String, nil)


# File ''

const :user_agent, T.nilable(String), default: nil

#viewFloat? (readonly)

Returns the value of prop view.

Returns:

  • (Float, nil)


# File ''

const :view, T.nilable(Float), default: nil

Instance Method Details

#to_hHash{LogStruct::LogField => T.untyped}

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/log_struct/log/request.rb', line 64

def to_h
  h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
  h[LogField::Path] = path unless path.nil?
  h[LogField::HttpMethod] = http_method unless http_method.nil?
  h[LogField::SourceIp] = source_ip unless source_ip.nil?
  h[LogField::UserAgent] = user_agent unless user_agent.nil?
  h[LogField::Referer] = referer unless referer.nil?
  h[LogField::Format] = format unless format.nil?
  h[LogField::Controller] = controller unless controller.nil?
  h[LogField::Action] = action unless action.nil?
  h[LogField::Status] = status unless status.nil?
  h[LogField::DurationMs] = duration_ms unless duration_ms.nil?
  h[LogField::View] = view unless view.nil?
  h[LogField::Database] = database unless database.nil?
  h[LogField::Params] = params unless params.nil?
  h[LogField::Host] = host unless host.nil?
  h[LogField::ContentType] = content_type unless content_type.nil?
  h[LogField::Accept] = accept unless accept.nil?
  h
end