Logstash 无法找到 log4j2.properties 配置文件
Logstash is unable to find log4j2.properties configuration file
在 windows 上尝试 运行 logstash 5 时:
C:\Development\workspace\logstash>C:\Development\Software\logstash-5.1.2\bin\logstash.bat
-f robot-log.js
它给出以下错误:
Could not find log4j2 configuration at path /Development/Software/logstash-5.1.2/config/log4j2.properties. Using default config which logs to console
15:03:53.667 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/aws"}
15:03:53.684 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bacula"}
15:03:53.693 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file ...
文件实际存在于目录中。为什么 logstash 找不到它?
注意:
我最初虽然这是 Ruby 使用 Linux 路径分隔符的问题。但是,正如@Stefan 在下面的评论中指出的那样,Ruby 即使在 Windows
上也接受 Linux 样式路径
这似乎是最新版本的 logstash 中的错误。在 logger.rb
下它有以下代码:
def self.initialize(config_location)
@@config_mutex.synchronize do
if @@logging_context.nil?
file_path = URI(config_location).path
if ::File.exists?(file_path)
logs_location = java.lang.System.getProperty("ls.logs")
puts "Sending Logstash's logs to #{logs_location} which is now configured via log4j2.properties"
@@logging_context = Configurator.initialize(nil, config_location)
else
# fall back to default config
puts "Could not find log4j2 configuration at path #{file_path}. Using default config which logs to console"
@@logging_context = Configurator.initialize(DefaultConfiguration.new)
end
end
end
end
对 URI.path
的调用似乎有问题,因为根据 documentation 它 returns /posts
当输入为 http://foo.com/posts?id=30&limit=5#time=1305298413
我不是 Ruby 程序员,所以我不知道为什么 logstash 开发人员在这里使用它。但是只需将 file_path = URI(config_location).path
替换为 file_path = config_location
就可以解决我的问题。
C:\Development\workspace\logstash>C:\Development\Software\logstash-5.1.2\bin\logstash.bat -f robot-log.js
Sending Logstash's logs to C:/Development/Software/logstash-5.1.2/logs which is now configured via log4j2.properties
[2017-01-24T15:22:04,754][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/aws"}
[2017-01-24T15:22:04,769][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bacula"}
[2017-01-24T15:22:04,772][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bro"}
在 windows 上尝试 运行 logstash 5 时:
C:\Development\workspace\logstash>C:\Development\Software\logstash-5.1.2\bin\logstash.bat -f robot-log.js
它给出以下错误:
Could not find log4j2 configuration at path /Development/Software/logstash-5.1.2/config/log4j2.properties. Using default config which logs to console
15:03:53.667 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/aws"}
15:03:53.684 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bacula"}
15:03:53.693 [[main]-pipeline-manager] INFO logstash.filters.multiline - Grok loading patterns from file ...
文件实际存在于目录中。为什么 logstash 找不到它?
注意: 我最初虽然这是 Ruby 使用 Linux 路径分隔符的问题。但是,正如@Stefan 在下面的评论中指出的那样,Ruby 即使在 Windows
上也接受 Linux 样式路径这似乎是最新版本的 logstash 中的错误。在 logger.rb
下它有以下代码:
def self.initialize(config_location)
@@config_mutex.synchronize do
if @@logging_context.nil?
file_path = URI(config_location).path
if ::File.exists?(file_path)
logs_location = java.lang.System.getProperty("ls.logs")
puts "Sending Logstash's logs to #{logs_location} which is now configured via log4j2.properties"
@@logging_context = Configurator.initialize(nil, config_location)
else
# fall back to default config
puts "Could not find log4j2 configuration at path #{file_path}. Using default config which logs to console"
@@logging_context = Configurator.initialize(DefaultConfiguration.new)
end
end
end
end
对 URI.path
的调用似乎有问题,因为根据 documentation 它 returns /posts
当输入为 http://foo.com/posts?id=30&limit=5#time=1305298413
我不是 Ruby 程序员,所以我不知道为什么 logstash 开发人员在这里使用它。但是只需将 file_path = URI(config_location).path
替换为 file_path = config_location
就可以解决我的问题。
C:\Development\workspace\logstash>C:\Development\Software\logstash-5.1.2\bin\logstash.bat -f robot-log.js
Sending Logstash's logs to C:/Development/Software/logstash-5.1.2/logs which is now configured via log4j2.properties
[2017-01-24T15:22:04,754][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/aws"}
[2017-01-24T15:22:04,769][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bacula"}
[2017-01-24T15:22:04,772][INFO ][logstash.filters.multiline] Grok loading patterns from file {:path=>"C:/Development/Software/logstash-5.1.2/vendor/bundle/jruby/1.9/gems/logstash-patterns-core-4.0.2/patterns/bro"}