Class: LogStruct::Log::Sidekiq
- Inherits:
-
T::Struct
- Object
- T::Struct
- LogStruct::Log::Sidekiq
- Extended by:
- T::Sig
- Includes:
- Interfaces::CommonFields, SerializeCommon
- Defined in:
- lib/log_struct/log/sidekiq.rb
Overview
Sidekiq log entry for structured logging
Constant Summary collapse
- SidekiqEvent =
Define valid event types for Sidekiq (currently only Log is used)
T.type_alias { Event::Log }
Instance Attribute Summary collapse
-
#context ⇒ Hash{Symbol => T.untyped}?
readonly
Returns the value of prop
context
. -
#event ⇒ SidekiqEvent
readonly
Returns the value of prop
event
. -
#level ⇒ Level
readonly
Returns the value of prop
level
. -
#message ⇒ String?
readonly
Returns the value of prop
message
. -
#process_id ⇒ Integer?
readonly
Sidekiq-specific fields.
-
#source ⇒ Source::Sidekiq
readonly
Common fields.
-
#thread_id ⇒ Integer, ...
readonly
Returns the value of prop
thread_id
. -
#timestamp ⇒ Time
readonly
Returns the value of prop
timestamp
.
Instance Method Summary collapse
- #initialize(source: T.let(Source::Sidekiq, Source::Sidekiq), event: T.let(Event::Log, SidekiqEvent), timestamp:, level: T.let(Level::Info, Level), process_id: nil, thread_id: nil, message: nil, context: nil) ⇒ void constructor
-
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization.
Methods included from SerializeCommon
Constructor Details
#initialize(source: T.let(Source::Sidekiq, Source::Sidekiq), event: T.let(Event::Log, SidekiqEvent), timestamp:, level: T.let(Level::Info, Level), process_id: nil, thread_id: nil, message: nil, context: nil) ⇒ void
|
# File '' const :source, Source::Sidekiq, default: T.let(Source::Sidekiq, Source::Sidekiq) const :event, SidekiqEvent, default: T.let(Event::Log, SidekiqEvent) const :timestamp, Time, factory: -> { Time.now } const :level, Level, default: T.let(Level::Info, Level) const :process_id, T.nilable(Integer), default: nil const :thread_id, T.nilable(T.any(Integer, String)), default: nil const :message, T.nilable(String), default: nil const :context, T.nilable(T::Hash[Symbol, T.untyped]), default: nil |
Instance Attribute Details
#context ⇒ Hash{Symbol => T.untyped}? (readonly)
Returns the value of prop context
.
|
# File '' const :context, T.nilable(T::Hash[Symbol, T.untyped]), default: nil |
#event ⇒ SidekiqEvent (readonly)
Returns the value of prop event
.
|
# File '' const :event, SidekiqEvent, default: T.let(Event::Log, SidekiqEvent) |
#level ⇒ Level (readonly)
Returns the value of prop level
.
|
# File '' const :level, Level, default: T.let(Level::Info, Level) |
#message ⇒ String? (readonly)
Returns the value of prop message
.
|
# File '' const :message, T.nilable(String), default: nil |
#process_id ⇒ Integer? (readonly)
Sidekiq-specific fields
|
# File '' const :process_id, T.nilable(Integer), default: nil |
#source ⇒ Source::Sidekiq (readonly)
Common fields
|
# File '' const :source, Source::Sidekiq, default: T.let(Source::Sidekiq, Source::Sidekiq) |
#thread_id ⇒ Integer, ... (readonly)
Returns the value of prop thread_id
.
|
# File '' const :thread_id, T.nilable(T.any(Integer, String)), default: nil |
#timestamp ⇒ Time (readonly)
Returns the value of prop timestamp
.
|
# File '' const :timestamp, Time, factory: -> { Time.now } |
Instance Method Details
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/log_struct/log/sidekiq.rb', line 37 def serialize(strict = true) hash = serialize_common(strict) # Add Sidekiq-specific fields if they're present hash[LOG_KEYS.fetch(:message)] = if hash[LOG_KEYS.fetch(:context)] = context if context hash[LOG_KEYS.fetch(:process_id)] = process_id if process_id hash[LOG_KEYS.fetch(:thread_id)] = thread_id if thread_id hash end |