Class: LogStruct::Log::Shrine

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

Overview

Shrine log entry for structured logging

Constant Summary collapse

ShrineEvent =
T.type_alias {
  T.any(
    Event::Upload,
    Event::Download,
    Event::Delete,
    Event::Metadata,
    Event::Exist,
    Event::Unknown
  )
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MergeAdditionalDataFields

#merge_additional_data_fields

Methods included from SerializeCommon

#as_json, #serialize_common

Constructor Details

#initialize(source: T.let(Source::Shrine, Source::Shrine), event:, timestamp:, level: T.let(Level::Info, Level), storage: nil, location: nil, upload_options: nil, download_options: nil, options: nil, uploader: nil, duration: nil, additional_data: {}) ⇒ void

Parameters:

  • source (Source::Shrine) (defaults to: T.let(Source::Shrine, Source::Shrine))

    Common fields

  • event (ShrineEvent)
  • timestamp (Time)
  • level (Level) (defaults to: T.let(Level::Info, Level))
  • storage (String, nil) (defaults to: nil)

    Shrine-specific fields

  • location (String, nil) (defaults to: nil)
  • upload_options (Hash{Symbol => T.untyped}, nil) (defaults to: nil)
  • download_options (Hash{Symbol => T.untyped}, nil) (defaults to: nil)
  • options (Hash{Symbol => T.untyped}, nil) (defaults to: nil)
  • uploader (String, nil) (defaults to: nil)
  • duration (Float, nil) (defaults to: nil)
  • additional_data (Hash{Symbol => T.untyped}) (defaults to: {})


# File ''

const :source, Source::Shrine, default: T.let(Source::Shrine, Source::Shrine)
const :event, ShrineEvent
const :timestamp, Time, factory: -> { Time.now }
const :level, Level, default: T.let(Level::Info, Level)
const :storage, T.nilable(String), default: nil
const :location, T.nilable(String), default: nil
const :upload_options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
const :download_options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
const :options, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
const :uploader, T.nilable(String), default: nil
const :duration, T.nilable(Float), default: nil
const :additional_data, T::Hash[Symbol, T.untyped], default: {}

Instance Attribute Details

#additional_dataHash{Symbol => T.untyped} (readonly)

Returns the value of prop additional_data.

Returns:

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


# File ''

const :additional_data, T::Hash[Symbol, T.untyped], default: {}

#download_optionsHash{Symbol => T.untyped}? (readonly)

Returns the value of prop download_options.

Returns:

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


# File ''

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

#durationFloat? (readonly)

Returns the value of prop duration.

Returns:

  • (Float, nil)


# File ''

const :duration, T.nilable(Float), default: nil

#eventShrineEvent (readonly)

Returns the value of prop event.

Returns:



# File ''

const :event, ShrineEvent

#levelLevel (readonly)

Returns the value of prop level.

Returns:



# File ''

const :level, Level, default: T.let(Level::Info, Level)

#locationString? (readonly)

Returns the value of prop location.

Returns:

  • (String, nil)


# File ''

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

#optionsHash{Symbol => T.untyped}? (readonly)

Returns the value of prop options.

Returns:

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


# File ''

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

#sourceSource::Shrine (readonly)

Common fields

Returns:



# File ''

const :source, Source::Shrine, default: T.let(Source::Shrine, Source::Shrine)

#storageString? (readonly)

Shrine-specific fields

Returns:

  • (String, nil)


# File ''

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

#timestampTime (readonly)

Returns the value of prop timestamp.

Returns:

  • (Time)


# File ''

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

#upload_optionsHash{Symbol => T.untyped}? (readonly)

Returns the value of prop upload_options.

Returns:

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


# File ''

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

#uploaderString? (readonly)

Returns the value of prop uploader.

Returns:

  • (String, nil)


# File ''

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

Instance Method Details

#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}

Convert the log entry to a hash for serialization

Parameters:

  • strict (Boolean) (defaults to: true)

Returns:

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


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/log_struct/log/shrine.rb', line 53

def serialize(strict = true)
  hash = serialize_common(strict)
  merge_additional_data_fields(hash)

  # Add Shrine-specific fields if they're present
  hash[LOG_KEYS.fetch(:storage)] = storage if storage
  hash[LOG_KEYS.fetch(:location)] = location if location
  hash[LOG_KEYS.fetch(:upload_options)] = upload_options if upload_options
  hash[LOG_KEYS.fetch(:download_options)] = download_options if download_options
  hash[LOG_KEYS.fetch(:options)] = options if options
  hash[LOG_KEYS.fetch(:uploader)] = uploader if uploader
  hash[LOG_KEYS.fetch(:duration)] = duration if duration

  hash
end