logstash-formatters 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ language: ruby
3
+ env:
4
+ global:
5
+ - PATH=$HOME/bin:$PATH
6
+ install: bundle install
7
+ script: bundle exec rspec
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - flintknappers+logstash-formatters@modcloth.com
data/AUTHORS.md ADDED
@@ -0,0 +1,5 @@
1
+ logstash4r authors
2
+ ==================
3
+
4
+ - Sheena Mccoy
5
+ - Jesse Szwedko
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,5 @@
1
+ Contributing to logstash4r
2
+ ==========================
3
+
4
+ Pull requests accepted! Please add your name to the `AUTHORS.md` file
5
+ alphabetically by last name.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ Copyright 2013 ModCloth, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ require 'logger'
2
+
3
+ module LogStashFormatters
4
+ class Json < ::Logger::Formatter
5
+ def call(severity, time, progname, message)
6
+ {
7
+ message: message,
8
+ severity: severity,
9
+ timestamp: time
10
+ }.to_json
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ require 'logger'
2
+
3
+ module LogStashFormatters
4
+ class JsonEvent < ::Logger::Formatter
5
+ def call(severity, time, progname, message)
6
+ event = default_message(severity)
7
+
8
+ unless message.is_a?(Hash)
9
+ message = {:@message => message.to_s}
10
+ end
11
+
12
+ message.each do |key, value|
13
+ if key == :@fields
14
+ event[:@fields] = value.merge(event[:@fields])
15
+ elsif (key.to_s[0] == '@')
16
+ event[key] = value
17
+ else
18
+ event[:@fields][key] = value
19
+ end
20
+ end
21
+
22
+ "#{event.to_json}\n"
23
+ end
24
+
25
+ def default_message(severity)
26
+ {
27
+ :@source => ::Socket::gethostname,
28
+ :@timestamp => Time.now,
29
+ :@tags => [],
30
+ :@fields => {severity: severity},
31
+ :@message => ''
32
+ }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'logstash-formatters'
7
+ s.version = '1.0.3'
8
+ s.authors = ['Jesse Szwedko', 'Sheena McCoy']
9
+ s.email = ['j.szwedko@modcloth.com', 'sp.mccoy@modcloth.com']
10
+ s.description= 'Logstash formatters for Ruby Logger'
11
+ s.summary = 'Logstash Formatters'
12
+ s.homepage = ''
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_development_dependency 'rspec'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'logstash_formatters/json_event'
2
+ require 'json'
3
+ require 'socket'
4
+
5
+ describe LogStashFormatters::JsonEvent do
6
+ let(:now) { Time.now }
7
+ let(:severity) { 'HIGH' }
8
+ let(:progname) { 'some name' }
9
+
10
+ describe "#format_message" do
11
+ it "formats message as JSON" do
12
+ subject.call(severity, now, progname, {:@message => 'test'}).should == {
13
+ :@source => ::Socket::gethostname,
14
+ :@timestamp => now,
15
+ :@tags => [],
16
+ :@fields => {severity: severity},
17
+ :@message => 'test'
18
+ }.to_json + "\n"
19
+ end
20
+ end
21
+ end
data/spec/json_spec.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'logstash_formatters/json'
2
+ require 'json'
3
+
4
+ describe LogStashFormatters::Json do
5
+ let(:now) { Time.now }
6
+ let(:severity) { 'HIGH' }
7
+ let(:progname) { 'some name' }
8
+
9
+ describe "#format_message" do
10
+ it "formats message as JSON" do
11
+ subject.call(severity, now, progname, {data: 'test'}).should == {
12
+ message: {data: 'test'},
13
+ severity: severity,
14
+ timestamp: now,
15
+ }.to_json
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -52,7 +52,18 @@ executables: []
52
52
  extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
+ - .gitignore
56
+ - .travis.yml
57
+ - AUTHORS.md
58
+ - CONTRIBUTING.md
59
+ - Gemfile
60
+ - LICENSE.md
55
61
  - lib/logstash_formatters.rb
62
+ - lib/logstash_formatters/json.rb
63
+ - lib/logstash_formatters/json_event.rb
64
+ - logstash-formatters.gemspec
65
+ - spec/json_event_spec.rb
66
+ - spec/json_spec.rb
56
67
  homepage: ''
57
68
  licenses:
58
69
  - MIT
@@ -78,5 +89,7 @@ rubygems_version: 1.8.23
78
89
  signing_key:
79
90
  specification_version: 3
80
91
  summary: Logstash Formatters
81
- test_files: []
92
+ test_files:
93
+ - spec/json_event_spec.rb
94
+ - spec/json_spec.rb
82
95
  has_rdoc: