Class: LogStruct::Log::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shared::SerializeCommon

#as_json, #serialize, #serialize_common

Methods included from Interfaces::CommonFields

#serialize

Methods included from Shared::MergeAdditionalDataFields

#merge_additional_data_fields

Constructor Details

#initialize(source:, event: Event::Error, timestamp:, level: Level::Info, error_class:, message:, backtrace: nil, additional_data: nil) ⇒ void

Parameters:

  • source (Source)

    Shared/common fields

  • event (Event) (defaults to: Event::Error)
  • timestamp (Time)
  • level (Level) (defaults to: Level::Info)
  • error_class (T.class_of(StandardError))

    Event-specific fields

  • message (String)
  • backtrace (Array<String>, nil) (defaults to: nil)
  • additional_data (Hash{String, Symbol => T.untyped}, nil) (defaults to: nil)


# File ''

const :source, Source
const :event, Event, default: Event::Error
const :timestamp, Time, factory: -> { Time.now }
const :level, Level, default: Level::Info
const :error_class, T.class_of(StandardError)
const :message, String
const :backtrace, T.nilable(T::Array[String]), default: nil
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil

Instance Attribute Details

#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

#backtraceArray<String>? (readonly)

Returns the value of prop backtrace.

Returns:

  • (Array<String>, nil)


# File ''

const :backtrace, T.nilable(T::Array[String]), default: nil

#error_classT.class_of(StandardError) (readonly)

Event-specific fields

Returns:

  • (T.class_of(StandardError))


# File ''

const :error_class, T.class_of(StandardError)

#eventEvent (readonly)

Returns the value of prop event.

Returns:



# File ''

const :event, Event, default: Event::Error

#levelLevel (readonly)

Returns the value of prop level.

Returns:



# File ''

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

#messageString (readonly)

Returns the value of prop message.

Returns:

  • (String)


# File ''

const :message, String

#sourceSource (readonly)

Shared/common fields

Returns:



# File ''

const :source, Source

#timestampTime (readonly)

Returns the value of prop timestamp.

Returns:

  • (Time)


# File ''

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

Instance Method Details

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

Returns:



46
47
48
49
50
51
52
# File 'lib/log_struct/log/error.rb', line 46

def to_h
  h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
  h[LogField::ErrorClass] = error_class
  h[LogField::Message] = message
  h[LogField::Backtrace] = backtrace unless backtrace.nil?
  h
end