From 238ef153e47934e653fc7ab16727460d6d538ba8 Mon Sep 17 00:00:00 2001 From: Karl Southern Date: Fri, 2 Sep 2016 19:01:28 +0100 Subject: [PATCH] Start of setup for Logstash's log4j2 integration --- Rakefile | 27 --------------------------- examples/cockroachdb.md | 18 ++++++++++++++++++ log4j2.xml | 17 +++++++++++++++++ logstash-output-jdbc.gemspec | 4 ++-- spec/jdbc_spec_helper.rb | 15 +++++++++++++-- 5 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 examples/cockroachdb.md create mode 100644 log4j2.xml diff --git a/Rakefile b/Rakefile index 0b3613e..dff0c3e 100644 --- a/Rakefile +++ b/Rakefile @@ -9,30 +9,3 @@ task :install_jars do ENV['JARS_VENDOR'] = 'false' Jars::Installer.new.vendor_jars!(false) end - -def colourize(text, color_code) - "\e[#{color_code}m#{text}\e[0m" -end - -desc 'Pre-release checks' -task :pre_release_checks do - - if `git status --porcelain`.chomp.length > 0 - warn colourize(' ✘ ', 31) + 'You have unstaged or uncommitted changes! Please only release from a clean working directory!' - else - puts colourize(" ✔ ", 32) + ' No un-staged commits' - end - - spec = Gem::Specification::load("logstash-output-jdbc.gemspec") - expected_tag_name = "v#{spec.version}" - - current_tag_name = `git describe --exact-match --tags HEAD 2>&1`.chomp - if $?.success? and current_tag_name == expected_tag_name - puts colourize(' ✔ ', 32) + 'Tag matches current HEAD' - elsif $?.success? and current_tag_name == expected_tag_name - warn colourize(' ✘ ', 31) + "Expected git tag to be '#{expected_tag_name}', but got '#{current_tag_name}'." - else - warn colourize(' ✘ ', 31) + "Expected git tag to be '#{expected_tag_name}, but got nothing." - end - -end diff --git a/examples/cockroachdb.md b/examples/cockroachdb.md new file mode 100644 index 0000000..fee0a7c --- /dev/null +++ b/examples/cockroachdb.md @@ -0,0 +1,18 @@ +# Example: CockroachDB + - Tested using postgresql-9.4.1209.jre6.jar + - **Warning** cockroach is known to throw a warning on connection test (at time of writing), thus the connection test is explicitly disabled. + +``` +input +{ + stdin { } +} +output { + jdbc { + driver_jar_path => '/opt/postgresql-9.4.1209.jre6.jar' + connection_test => false + connection_string => 'jdbc:postgresql://127.0.0.1:26257/test?user=root' + statement => [ "INSERT INTO log (host, timestamp, message) VALUES(?, CAST (? AS timestamp), ?)", "host", "@timestamp", "message" ] + } +} +``` diff --git a/log4j2.xml b/log4j2.xml new file mode 100644 index 0000000..07a1fc3 --- /dev/null +++ b/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/logstash-output-jdbc.gemspec b/logstash-output-jdbc.gemspec index a558d59..b1f067a 100644 --- a/logstash-output-jdbc.gemspec +++ b/logstash-output-jdbc.gemspec @@ -22,11 +22,11 @@ Gem::Specification.new do |s| s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'output' } # Gem dependencies - s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.0' + s.add_runtime_dependency 'logstash-core-plugin-api', '>= 1.60', '<= 2.99' s.add_runtime_dependency 'stud' s.add_runtime_dependency 'logstash-codec-plain' - s.requirements << "jar 'com.zaxxer:HikariCP', '2.4.6'" + s.requirements << "jar 'com.zaxxer:HikariCP', '2.4.7'" s.requirements << "jar 'org.slf4j:slf4j-log4j12', '1.7.21'" s.add_development_dependency 'jar-dependencies' diff --git a/spec/jdbc_spec_helper.rb b/spec/jdbc_spec_helper.rb index b3c618b..2cfd548 100644 --- a/spec/jdbc_spec_helper.rb +++ b/spec/jdbc_spec_helper.rb @@ -20,7 +20,9 @@ RSpec.shared_context 'when initializing' do end RSpec.shared_context 'when outputting messages' do - let(:logger) { double("logger") } + let(:logger) { + double("logger") + } let(:jdbc_test_table) do 'logstash_output_jdbc_test' @@ -50,7 +52,16 @@ RSpec.shared_context 'when outputting messages' do let(:plugin) do # Setup logger - expect(LogStash::Ouputs::Jdbc).to receive(:logger).and_return(logger).at_least(:once) + allow(LogStash::Outputs::Jdbc).to receive(:logger).and_return(logger) + + # XXX: Suppress reflection logging. There has to be a better way around this. + allow(logger).to receive(:debug).with(/config LogStash::/) + + # Suppress beta warnings. + allow(logger).to receive(:info).with(/Please let us know if you find bugs or have suggestions on how to improve this plugin./) + + # Suppress start up messages. + expect(logger).to receive(:info).once.with(/JDBC - Starting up/) # Setup plugin output = LogStash::Plugin.lookup('output', 'jdbc').new(jdbc_settings)