<commit_before>udp_logger = ::LogStashLogger.new(port: 5228)

ActiveSupport::Notifications.subscribe(/fragment|process_action.action_controller|racing_on_rails/) do |name, start, finish, id, payload|
  message = {
    current_person_name: ::Person.current.try(:name),
    current_person_id: ::Person.current.try(:id),
    duration: (finish - start),
    id: id,
    message: name,
    racing_association: RacingAssociation.current.short_name,
    start: start
  }.merge(payload)

  # Ideally, would traverse params and fix encodings
  begin
    udp_logger.info message
  rescue Encoding::UndefinedConversionError => e
    Rails.logger.debug "[#{Time.zone.now}] (#{e}) logging to Logstash #{message[:params]}"
    message.delete(:params)
    udp_logger.info message
  end
end<commit_msg>Only use Logstash UDP logger in staging and prod<commit_after>if Rails.env.production? || Rails.env.staging?
  udp_logger = ::LogStashLogger.new(port: 5228)

  ActiveSupport::Notifications.subscribe(/fragment|process_action.action_controller|racing_on_rails/) do |name, start, finish, id, payload|
    message = {
      current_person_name: ::Person.current.try(:name),
      current_person_id: ::Person.current.try(:id),
      duration: (finish - start),
      id: id,
      message: name,
      racing_association: RacingAssociation.current.short_name,
      start: start
    }.merge(payload)

    # Ideally, would traverse params and fix encodings
    begin
      udp_logger.info message
    rescue Encoding::UndefinedConversionError => e
      Rails.logger.debug "[#{Time.zone.now}] (#{e}) logging to Logstash #{message[:params]}"
      message.delete(:params)
      udp_logger.info message
    end
  end
end
{'fraction_non_alphanumeric': 0.12014134275618374, 'fraction_numerical': 0.004711425206124852, 'mean_word_length': 4.179878048780488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '343518', 'n_tokens_mistral': 542, 'n_tokens_neox': 524, 'n_words': 115}