Module: LogStruct::Integrations::CarrierWave::LoggingMethods

Extended by:
T::Helpers, T::Sig
Defined in:
lib/log_struct/integrations/carrierwave.rb

Overview

Methods to add logging to CarrierWave operations

Instance Method Summary collapse

Instance Method Details

#retrieve_from_store!(identifier, *args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/log_struct/integrations/carrierwave.rb', line 76

def retrieve_from_store!(identifier, *args)
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = super
  Process.clock_gettime(Process::CLOCK_MONOTONIC)

  # Extract file information if available
  file_size = file.size if file&.respond_to?(:size)

  # Log the retrieve operation with structured data
  log_data = Log::CarrierWave::Download.new(
    storage: storage.class.name.split("::").last.downcase.to_sym,
    file_id: identifier,
    filename: file&.filename,
    mime_type: file&.content_type,
    size: file_size,
    # No duration field on Download event schema
    uploader: self.class.name,
    model: model.class.name,
    mount_point: mounted_as.to_s,
    version: version_name.to_s,
    store_path: store_path,
    extension: file&.extension
  )

  ::Rails.logger.info(log_data)
  result
end

#store!(*args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/log_struct/integrations/carrierwave.rb', line 38

def store!(*args)
  start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result = super
  duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time

  # Extract file information
  file_size = file.size if file.respond_to?(:size)
  {
    identifier: identifier,
    filename: file.filename,
    content_type: file.content_type,
    size: file_size,
    store_path: store_path,
    extension: file.extension
  }

  # Log the store operation with structured data
  log_data = Log::CarrierWave::Upload.new(
    storage: storage.class.name.split("::").last.downcase.to_sym,
    file_id: identifier,
    filename: file.filename,
    mime_type: file.content_type,
    size: file_size,
    duration_ms: (duration * 1000.0).to_f,
    uploader: self.class.name,
    model: model.class.name,
    mount_point: mounted_as.to_s,
    version: version_name.to_s,
    store_path: store_path,
    extension: file.extension
  )

  ::Rails.logger.info(log_data)
  result
end