Start of setup for Logstash's log4j2 integration

This commit is contained in:
Karl Southern 2016-09-02 19:01:28 +01:00
parent 3bdd8ef3a8
commit 238ef153e4
5 changed files with 50 additions and 31 deletions

View File

@ -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

18
examples/cockroachdb.md Normal file
View File

@ -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" ]
}
}
```

17
log4j2.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<File name="file" fileName="log4j2.log">
<PatternLayout pattern="%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<!-- If we need to figure out whats happening for development purposes, disable this -->
<Logger name="com.zaxxer.hikari" level="off" />
<Root level="debug">
<AppenderRef ref="file"/>
</Root>
</Loggers>
</Configuration>

View File

@ -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'

View File

@ -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)