Class: LogStruct::Log::CarrierWave

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

Overview

CarrierWave log entry for structured logging

Constant Summary collapse

CarrierWaveEvent =
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::CarrierWave, Source::CarrierWave), event:, timestamp:, level: T.let(Level::Info, Level), operation: nil, storage: nil, file_id: nil, filename: nil, mime_type: nil, size: nil, metadata: nil, duration: nil, uploader: nil, model: nil, mount_point: nil, additional_data: {}) ⇒ void

Parameters:

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

    Common fields

  • event (CarrierWaveEvent)
  • timestamp (Time)
  • level (Level) (defaults to: T.let(Level::Info, Level))
  • operation (Symbol, nil) (defaults to: nil)

    File-specific fields

  • storage (String, nil) (defaults to: nil)
  • file_id (String, nil) (defaults to: nil)
  • filename (String, nil) (defaults to: nil)
  • mime_type (String, nil) (defaults to: nil)
  • size (Integer, nil) (defaults to: nil)
  • metadata (Hash{String => T.untyped}, nil) (defaults to: nil)
  • duration (Float, nil) (defaults to: nil)
  • uploader (String, nil) (defaults to: nil)

    CarrierWave-specific fields

  • model (String, nil) (defaults to: nil)
  • mount_point (String, nil) (defaults to: nil)
  • additional_data (Hash{Symbol => T.untyped}) (defaults to: {})


# File ''

const :source, Source::CarrierWave, default: T.let(Source::CarrierWave, Source::CarrierWave)
const :event, CarrierWaveEvent
const :timestamp, Time, factory: -> { Time.now }
const :level, Level, default: T.let(Level::Info, Level)
const :operation, T.nilable(Symbol), default: nil
const :storage, T.nilable(String), default: nil
const :file_id, T.nilable(String), default: nil
const :filename, T.nilable(String), default: nil
const :mime_type, T.nilable(String), default: nil
const :size, T.nilable(Integer), default: nil
const :metadata, T.nilable(T::Hash[String, T.untyped]), default: nil
const :duration, T.nilable(Float), default: nil
const :uploader, T.nilable(String), default: nil
const :model, T.nilable(String), default: nil
const :mount_point, T.nilable(String), 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: {}

#durationFloat? (readonly)

Returns the value of prop duration.

Returns:

  • (Float, nil)


# File ''

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

#eventCarrierWaveEvent (readonly)

Returns the value of prop event.

Returns:



# File ''

const :event, CarrierWaveEvent

#file_idString? (readonly)

Returns the value of prop file_id.

Returns:

  • (String, nil)


# File ''

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

#filenameString? (readonly)

Returns the value of prop filename.

Returns:

  • (String, nil)


# File ''

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

#levelLevel (readonly)

Returns the value of prop level.

Returns:



# File ''

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

#metadataHash{String => T.untyped}? (readonly)

Returns the value of prop metadata.

Returns:

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


# File ''

const :metadata, T.nilable(T::Hash[String, T.untyped]), default: nil

#mime_typeString? (readonly)

Returns the value of prop mime_type.

Returns:

  • (String, nil)


# File ''

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

#modelString? (readonly)

Returns the value of prop model.

Returns:

  • (String, nil)


# File ''

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

#mount_pointString? (readonly)

Returns the value of prop mount_point.

Returns:

  • (String, nil)


# File ''

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

#operationSymbol? (readonly)

File-specific fields

Returns:

  • (Symbol, nil)


# File ''

const :operation, T.nilable(Symbol), default: nil

#sizeInteger? (readonly)

Returns the value of prop size.

Returns:

  • (Integer, nil)


# File ''

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

#sourceSource::CarrierWave (readonly)

Common fields

Returns:



# File ''

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

#storageString? (readonly)

Returns the value of prop storage.

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 }

#uploaderString? (readonly)

CarrierWave-specific fields

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})


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/log_struct/log/carrierwave.rb', line 59

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

  # Add file-specific fields if they're present
  hash[LOG_KEYS.fetch(:storage)] = storage if storage
  hash[LOG_KEYS.fetch(:operation)] = operation if operation
  hash[LOG_KEYS.fetch(:file_id)] = file_id if file_id
  hash[LOG_KEYS.fetch(:filename)] = filename if filename
  hash[LOG_KEYS.fetch(:mime_type)] = mime_type if mime_type
  hash[LOG_KEYS.fetch(:size)] = size if size
  hash[LOG_KEYS.fetch(:metadata)] =  if 
  hash[LOG_KEYS.fetch(:duration)] = duration if duration

  # Add CarrierWave-specific fields if they're present
  hash[LOG_KEYS.fetch(:uploader)] = uploader if uploader
  hash[LOG_KEYS.fetch(:model)] = model if model
  hash[LOG_KEYS.fetch(:mount_point)] = mount_point if mount_point

  hash
end