Class: LogStruct::Log::Plain
- Inherits:
-
T::Struct
- Object
- T::Struct
- LogStruct::Log::Plain
- Extended by:
- T::Sig
- Includes:
- Interfaces::AdditionalDataField, Interfaces::CommonFields, MergeAdditionalDataFields, SerializeCommon
- Defined in:
- lib/log_struct/log/plain.rb
Overview
Plain log entry for structured logging
Constant Summary collapse
Instance Attribute Summary collapse
-
#additional_data ⇒ Hash{Symbol => T.untyped}
readonly
Allow people to submit additional data.
-
#event ⇒ PlainEvent
readonly
Returns the value of prop
event
. -
#level ⇒ Level
readonly
Returns the value of prop
level
. -
#message ⇒ T.untyped
readonly
Plain log messages can be any type (String, Number, Array, Hash, etc.) Developers might do something like Rails.logger.info(123) or Rails.logger.info(@variable) when debugging, or gems might send all kinds of random stuff to the logger.
-
#source ⇒ Source
readonly
Common fields.
-
#timestamp ⇒ Time
readonly
Returns the value of prop
timestamp
.
Instance Method Summary collapse
- #initialize(source: T.let(Source::App, Source), event: T.let(Event::Log, PlainEvent), level: T.let(Level::Info, Level), timestamp:, message:, additional_data: {}) ⇒ void constructor
-
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization.
Methods included from MergeAdditionalDataFields
Methods included from SerializeCommon
Constructor Details
#initialize(source: T.let(Source::App, Source), event: T.let(Event::Log, PlainEvent), level: T.let(Level::Info, Level), timestamp:, message:, additional_data: {}) ⇒ void
|
# File '' const :source, Source, default: T.let(Source::App, Source) const :event, PlainEvent, default: T.let(Event::Log, PlainEvent) const :level, Level, default: T.let(Level::Info, Level) const :timestamp, Time, factory: -> { Time.now } const :message, T.untyped const :additional_data, T::Hash[Symbol, T.untyped], default: {} |
Instance Attribute Details
#additional_data ⇒ Hash{Symbol => T.untyped} (readonly)
Allow people to submit additional data
|
# File '' const :additional_data, T::Hash[Symbol, T.untyped], default: {} |
#event ⇒ PlainEvent (readonly)
Returns the value of prop event
.
|
# File '' const :event, PlainEvent, default: T.let(Event::Log, PlainEvent) |
#level ⇒ Level (readonly)
Returns the value of prop level
.
|
# File '' const :level, Level, default: T.let(Level::Info, Level) |
#message ⇒ T.untyped (readonly)
Plain log messages can be any type (String, Number, Array, Hash, etc.) Developers might do something like Rails.logger.info(123) or Rails.logger.info(@variable) when debugging, or gems might send all kinds of random stuff to the logger. We don't want to crash with a type error in any of these cases.
|
# File '' const :message, T.untyped |
#source ⇒ Source (readonly)
Common fields
|
# File '' const :source, Source, default: T.let(Source::App, Source) |
#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
45 46 47 48 49 50 |
# File 'lib/log_struct/log/plain.rb', line 45 def serialize(strict = true) hash = serialize_common(strict) merge_additional_data_fields(hash) hash[LOG_KEYS.fetch(:message)] = hash end |