<commit_before><commit_msg>Added a filter to add fields from environment variables<commit_after>require "logstash/filters/base"
require "logstash/namespace"

# Set fields from environment variables
class LogStash::Filters::Environment < LogStash::Filters::Base
  config_name "environment"
  plugin_status "stable"

  # Specify a hash of fields to the environment variable
  # A hash of matches of field => environment variable
  config :add_field_from_env, :validate => :hash, :default => {}

  public
  def register
    # Nothing
  end # def register

  public
  def filter(event)
    return unless filter?(event)
    @add_field_from_env.each do |field, env|
      event.fields[field] = ENV[env]
    end
    filter_matched(event)
  end # def filter
end # class LogStash::Filters::Environment
{'fraction_non_alphanumeric': 0.08712121212121213, 'fraction_numerical': 0.0, 'mean_word_length': 4.545454545454546, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '4210339', 'n_tokens_mistral': 229, 'n_tokens_neox': 229, 'n_words': 73}