class ActiveStorage::LogSubscriber

def debug(event, colored_message)

def debug(event, colored_message)
  super log_prefix_for_service(event) + colored_message
end

def info(event, colored_message)

def info(event, colored_message)
  super log_prefix_for_service(event) + colored_message
end

def key_in(event)

def key_in(event)
  event.payload[:key]
end

def log_prefix_for_service(event)

def log_prefix_for_service(event)
  color "  #{event.payload[:service]} Storage (#{event.duration.round(1)}ms) ", CYAN
end

def logger

def logger
  ActiveStorage.logger
end

def service_delete(event)

def service_delete(event)
  info event, color("Deleted file from key: #{key_in(event)}", RED)
end

def service_delete_prefixed(event)

def service_delete_prefixed(event)
  info event, color("Deleted files by key prefix: #{event.payload[:prefix]}", RED)
end

def service_download(event)

def service_download(event)
  info event, color("Downloaded file from key: #{key_in(event)}", BLUE)
end

def service_exist(event)

def service_exist(event)
  debug event, color("Checked if file exists at key: #{key_in(event)} (#{event.payload[:exist] ? "yes" : "no"})", BLUE)
end

def service_mirror(event)

def service_mirror(event)
  message = "Mirrored file at key: #{key_in(event)}"
  message += " (checksum: #{event.payload[:checksum]})" if event.payload[:checksum]
  debug event, color(message, GREEN)
end

def service_upload(event)

def service_upload(event)
  message = "Uploaded file to key: #{key_in(event)}"
  message += " (checksum: #{event.payload[:checksum]})" if event.payload[:checksum]
  info event, color(message, GREEN)
end

def service_url(event)

def service_url(event)
  debug event, color("Generated URL for file at key: #{key_in(event)} (#{event.payload[:url]})", BLUE)
end