Class: LogStash::Filters::Language

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/language.rb

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/logstash/filters/language.rb', line 55

def filter(event)
  ## Concatinate fields
  checkValue = []

  @logger.debug("Checking language in #{@fields}")

  # Put all fields for language detection into checkValue
  @fields.each { |v|
    unless event[v].nil?
      checkValue << event[v]
    end
  }

  unless checkValue.nil?
    if checkValue.join(' ').length >= @amount_of_chars
      language = CLD.detect_language(checkValue.join(' '))
      @logger.debug("Language values are #{language}")
      event['detected_lang'] = language[:code]
      event['lang_reliability'] = language[:reliable]
      if @concat_fields
        event["#{@concat_prefix}_#{language[:code]}"] = checkValue.join(' ')
      end
    end
  end
  # filter_matched should go in the last line of our successful code
  filter_matched(event)
end

#registerObject



51
52
# File 'lib/logstash/filters/language.rb', line 51

def register
end