Class: LogStruct::Log::Sidekiq::Log

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

Constant Summary

Constants included from LogStruct::Log::Shared::MergeAdditionalDataFields

LogStruct::Log::Shared::MergeAdditionalDataFields::RESERVED_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogStruct::Log::Shared::SerializeCommon

#as_json, #serialize, #serialize_common

Methods included from Interfaces::CommonFieldBase

#serialize

Methods included from LogStruct::Log::Shared::MergeAdditionalDataFields

#merge_additional_data_fields

Constructor Details

#initialize(source: Source::Sidekiq, event: Event::Log, timestamp:, level: Level::Info, message: nil, context: nil, process_id: nil, thread_id: nil, additional_data: nil) ⇒ void

Parameters:

  • source (Source::Sidekiq) (defaults to: Source::Sidekiq) —

    Shared/common fields

  • event (Event) (defaults to: Event::Log)
  • timestamp (Time)
  • level (Level) (defaults to: Level::Info)
  • message (String, nil) (defaults to: nil) —

    Event-specific fields

  • context (Hash{Symbol => T.untyped}, nil) (defaults to: nil)
  • process_id (Integer, nil) (defaults to: nil)
  • thread_id (Integer, String, nil) (defaults to: nil)
  • additional_data (Hash{String, Symbol => T.untyped}, nil) (defaults to: nil)


# File ''

const :source, Source::Sidekiq, default: Source::Sidekiq
const :event, Event, default: Event::Log
const :timestamp, Time, factory: -> { Time.now }
const :level, Level, default: Level::Info
const :message, T.nilable(String), default: nil
const :context, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
const :process_id, T.nilable(Integer), default: nil
const :thread_id, T.nilable(T.any(Integer, String)), default: nil
const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil

Instance Attribute Details

#additional_data ⇒ Hash{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

#context ⇒ Hash{Symbol => T.untyped}? (readonly)

Returns the value of prop context.

Returns:

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


# File ''

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

#event ⇒ Event (readonly)

Returns the value of prop event.

Returns:



# File ''

const :event, Event, default: Event::Log

#level ⇒ Level (readonly)

Returns the value of prop level.

Returns:



# File ''

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

#message ⇒ String? (readonly)

Event-specific fields

Returns:

  • (String, nil)


# File ''

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

#process_id ⇒ Integer? (readonly)

Returns the value of prop process_id.

Returns:

  • (Integer, nil)


# File ''

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

#source ⇒ Source::Sidekiq (readonly)

Shared/common fields

Returns:



# File ''

const :source, Source::Sidekiq, default: Source::Sidekiq

#thread_id ⇒ Integer, ... (readonly)

Returns the value of prop thread_id.

Returns:

  • (Integer, String, nil)


# File ''

const :thread_id, T.nilable(T.any(Integer, String)), default: nil

#timestamp ⇒ Time (readonly)

Returns the value of prop timestamp.

Returns:

  • (Time)


# File ''

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

Instance Method Details

#to_h ⇒ Hash{LogStruct::LogField => T.untyped}

Returns:



48
49
50
51
52
53
54
55
# File 'lib/log_struct/log/sidekiq/log.rb', line 48

def to_h
  h = T.let({}, T::Hash[LogStruct::LogField, T.untyped])
  h[LogField::Message] = message unless message.nil?
  h[LogField::Context] = context unless context.nil?
  h[LogField::ProcessId] = process_id unless process_id.nil?
  h[LogField::ThreadId] = thread_id unless thread_id.nil?
  h
end