无法加载 Java 类 uk.co.jaywayco.Parser



我正在尝试编写一个自定义日志过滤器。我已经遵循了这里的文档。

我的过滤器(目前)如下所示:

# Call this file 'foo.rb' (in logstash/filters, as above)
require "logstash/filters/base"
require "logstash/namespace"
class LogStash::Filters::NLP < LogStash::Filters::Base
  # Setting the config_name here is required. This is how you
  # configure this filter from your logstash config.
  #
  # filter {
  #   foo { ... }
  # }
  config_name "nlp"
  # New plugins should start life at milestone 1.
  milestone 1
  # Replace the message with this value.
  config :message, :validate => :string
  public
  def register
    # nothing to do
    java_import 'uk.co.jaywayco.Parser'
  end # def register
  public
  def filter(event)
    # return nothing unless there's an actual filter event
    return unless filter?(event)
    if @message
      # Replace the event message with our message as configured in the
      # config file.
      event["message"] = @message
    end
    # filter_matched should go in the last line of our successful code
    filter_matched(event)
  end # def filter
end # class LogStash::Filters::NLP

我创建了一个非常简单的logstash配置,看起来像这样:

input {
  stdin { type => "nlp" }
}
filter {
  if [type] == "nlp" {
    nlp {
      message => "Hello world! - Youve been NLP'd"
    }
  }
}
output {
  stdout { }
}

当我使用以下命令运行日志时:

bin/logstash -f /etc/logstash/conf.d/test.conf

我收到以下错误:

The error reported is:
    enter code herecannot load Java class uk.co.jaywayco.Parser

Java 类uk.co.jaywayco.Parser位于 /opt/logstash/lib/logstash/filters 文件夹中的 jar 文件中。这是所有过滤器脚本所在的位置。

为什么 logstash 不会加载我的 java 类?

好的,

感谢logstash IRC频道

解决方案是添加require 'logstash/filters/myjarfile.jar'其他require

最新更新