Class: LogStruct::Log::Request
- Inherits:
-
T::Struct
- Object
- T::Struct
- LogStruct::Log::Request
- Extended by:
- T::Sig
- Defined in:
- lib/log_struct/log/request.rb
Overview
Request log entry for structured logging
Constant Summary collapse
Instance Attribute Summary collapse
-
#action ⇒ String?
readonly
Returns the value of prop
action
. -
#controller ⇒ String?
readonly
Returns the value of prop
controller
. -
#db ⇒ Float?
readonly
Returns the value of prop
db
. -
#duration ⇒ Float?
readonly
Returns the value of prop
duration
. -
#event ⇒ RequestEvent
readonly
Returns the value of prop
event
. -
#format ⇒ String?
readonly
Returns the value of prop
format
. -
#http_method ⇒ String?
readonly
Request-specific fields NOTE:
method
is a reserved word, so we usehttp_method
prop while settingmethod
in the serialized output. -
#level ⇒ Level
readonly
Returns the value of prop
level
. -
#params ⇒ Hash{Symbol => T.untyped}?
readonly
Returns the value of prop
params
. -
#path ⇒ String?
readonly
Returns the value of prop
path
. -
#referer ⇒ String?
readonly
Returns the value of prop
referer
. -
#request_id ⇒ String?
readonly
Returns the value of prop
request_id
. -
#source ⇒ Source::Rails
readonly
Common fields.
-
#source_ip ⇒ String?
readonly
Returns the value of prop
source_ip
. -
#status ⇒ Integer?
readonly
Returns the value of prop
status
. -
#timestamp ⇒ Time
readonly
Returns the value of prop
timestamp
. -
#user_agent ⇒ String?
readonly
Returns the value of prop
user_agent
. -
#view ⇒ Float?
readonly
Returns the value of prop
view
.
Instance Method Summary collapse
- #initialize(source: T.let(Source::Rails, Source::Rails), event: T.let(Event::Request, RequestEvent), timestamp:, level: T.let(Level::Info, Level), http_method: nil, path: nil, format: nil, controller: nil, action: nil, status: nil, duration: nil, view: nil, db: nil, params: nil, source_ip: nil, user_agent: nil, referer: nil, request_id: nil) ⇒ void constructor
-
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization.
Methods included from AddRequestFields
Methods included from SerializeCommon
Constructor Details
#initialize(source: T.let(Source::Rails, Source::Rails), event: T.let(Event::Request, RequestEvent), timestamp:, level: T.let(Level::Info, Level), http_method: nil, path: nil, format: nil, controller: nil, action: nil, status: nil, duration: nil, view: nil, db: nil, params: nil, source_ip: nil, user_agent: nil, referer: nil, request_id: nil) ⇒ void
|
# File '' const :source, Source::Rails, default: T.let(Source::Rails, Source::Rails) const :event, RequestEvent, default: T.let(Event::Request, RequestEvent) const :timestamp, Time, factory: -> { Time.now } const :level, Level, default: T.let(Level::Info, Level) const :http_method, T.nilable(String), default: nil const :path, T.nilable(String), default: nil const :format, T.nilable(String), 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, T.nilable(Float), default: nil const :view, T.nilable(Float), default: nil const :db, T.nilable(Float), default: nil const :params, T.nilable(T::Hash[Symbol, T.untyped]), 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 :request_id, T.nilable(String), default: nil |
Instance Attribute Details
#action ⇒ String? (readonly)
Returns the value of prop action
.
|
# File '' const :action, T.nilable(String), default: nil |
#controller ⇒ String? (readonly)
Returns the value of prop controller
.
|
# File '' const :controller, T.nilable(String), default: nil |
#db ⇒ Float? (readonly)
Returns the value of prop db
.
|
# File '' const :db, T.nilable(Float), default: nil |
#duration ⇒ Float? (readonly)
Returns the value of prop duration
.
|
# File '' const :duration, T.nilable(Float), default: nil |
#event ⇒ RequestEvent (readonly)
Returns the value of prop event
.
|
# File '' const :event, RequestEvent, default: T.let(Event::Request, RequestEvent) |
#format ⇒ String? (readonly)
Returns the value of prop format
.
|
# File '' const :format, T.nilable(String), default: nil |
#http_method ⇒ String? (readonly)
Request-specific fields
NOTE: method
is a reserved word, so we use http_method
prop while setting method
in the serialized output
|
# File '' const :http_method, T.nilable(String), default: nil |
#level ⇒ Level (readonly)
Returns the value of prop level
.
|
# File '' const :level, Level, default: T.let(Level::Info, Level) |
#params ⇒ Hash{Symbol => T.untyped}? (readonly)
Returns the value of prop params
.
|
# File '' const :params, T.nilable(T::Hash[Symbol, T.untyped]), default: nil |
#path ⇒ String? (readonly)
Returns the value of prop path
.
|
# File '' const :path, T.nilable(String), default: nil |
#referer ⇒ String? (readonly)
Returns the value of prop referer
.
|
# File '' const :referer, T.nilable(String), default: nil |
#request_id ⇒ String? (readonly)
Returns the value of prop request_id
.
|
# File '' const :request_id, T.nilable(String), default: nil |
#source ⇒ Source::Rails (readonly)
Common fields
|
# File '' const :source, Source::Rails, default: T.let(Source::Rails, Source::Rails) |
#source_ip ⇒ String? (readonly)
Returns the value of prop source_ip
.
|
# File '' const :source_ip, T.nilable(String), default: nil |
#status ⇒ Integer? (readonly)
Returns the value of prop status
.
|
# File '' const :status, T.nilable(Integer), default: nil |
#timestamp ⇒ Time (readonly)
Returns the value of prop timestamp
.
|
# File '' const :timestamp, Time, factory: -> { Time.now } |
#user_agent ⇒ String? (readonly)
Returns the value of prop user_agent
.
|
# File '' const :user_agent, T.nilable(String), default: nil |
#view ⇒ Float? (readonly)
Returns the value of prop view
.
|
# File '' const :view, T.nilable(Float), default: nil |
Instance Method Details
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/log_struct/log/request.rb', line 54 def serialize(strict = true) hash = serialize_common(strict) add_request_fields(hash) hash[LOG_KEYS.fetch(:http_method)] = http_method if http_method hash[LOG_KEYS.fetch(:path)] = path if path hash[LOG_KEYS.fetch(:format)] = format if format hash[LOG_KEYS.fetch(:controller)] = controller if controller hash[LOG_KEYS.fetch(:action)] = action if action hash[LOG_KEYS.fetch(:status)] = status if status hash[LOG_KEYS.fetch(:duration)] = duration if duration hash[LOG_KEYS.fetch(:view)] = view if view hash[LOG_KEYS.fetch(:db)] = db if db hash[LOG_KEYS.fetch(:params)] = params if params hash[LOG_KEYS.fetch(:source_ip)] = source_ip if source_ip hash[LOG_KEYS.fetch(:user_agent)] = user_agent if user_agent hash[LOG_KEYS.fetch(:referer)] = referer if referer hash[LOG_KEYS.fetch(:request_id)] = request_id if request_id hash end |