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) ⇒ T.untyped

Log file retrieve operations

Parameters:

  • identifier (T.untyped)
  • args (T.untyped)

Returns:

  • (T.untyped)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/log_struct/integrations/carrierwave.rb', line 80

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

  # 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.new(
    source: Source::CarrierWave,
    event: Event::Download,
    duration: duration * 1000.0, # Convert to ms
    uploader: self.class.name,
    storage: storage.class.name,
    mount_point: mounted_as.to_s,
    file_id: identifier,
    filename: file&.filename,
    mime_type: file&.content_type,
    size: file_size,
    additional_data: {
      version: version_name.to_s
    }
  )

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

#store!(*args) ⇒ T.untyped

Log file storage operations

Parameters:

  • args (T.untyped)

Returns:

  • (T.untyped)


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
73
74
75
76
# 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.new(
    source: Source::CarrierWave,
    event: Event::Upload,
    duration: duration * 1000.0, # Convert to ms
    model: model.class.name,
    uploader: self.class.name,
    storage: storage.class.name,
    mount_point: mounted_as.to_s,
    filename: file.filename,
    mime_type: file.content_type,
    size: file_size,
    file_id: identifier,
    additional_data: {
      version: version_name.to_s,
      store_path: store_path,
      extension: file.extension
    }
  )

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