logstash_scribbler 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b85417a19a572d31ba7b9b8189e5e68d7713adef
4
+ data.tar.gz: 45a8486a13282a99514bfa793d5cf9a0c13515ab
5
+ SHA512:
6
+ metadata.gz: c2ecef724413e9d1f9470a7af054a06395a8c9907b74dc6e4adce3cf93cd82bcee3dd61e2fc57c1a9cd2d1c6a82e877bacecec262536523c64c36253847fec79
7
+ data.tar.gz: cc50fece87690cf8f377844d957c7d253b176924fc5b555b9002502a555a35f8d9fdd81c8d9df3b67950b1f7ebaadfc8856099a0ce3f98fd7211f479fbef40b1
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.octopolo.yml ADDED
@@ -0,0 +1,4 @@
1
+ github_repo: sportngin/logstash_scribbler
2
+ semantic_versioning: true
3
+ branches_to_keep:
4
+ - master
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.soyuz.yml ADDED
@@ -0,0 +1,13 @@
1
+ defaults:
2
+ deploy_cmd: gem push *.gem
3
+ before_deploy_cmds:
4
+ - /usr/local/bin/op tag-release
5
+ - sed -i "" -e "s/\".*/\"$(git tag| sort -n -t. -k1,1 -k2,2 -k3,3 | tail -1 | sed s/v//)\"/" lib/logstash_scribbler/version.rb
6
+ - git add lib/logstash_scribbler/version.rb
7
+ - git commit -m "Version Bump" && git push
8
+ - gem build logstash_scribbler.gemspec
9
+ after_deploy_cmds:
10
+ - rm *.gem
11
+ environments:
12
+ -
13
+ rubygems: {}
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 1.9.3
6
+ script: bundle exec rspec
@@ -0,0 +1,2 @@
1
+ #### 0.0.2
2
+ #### 0.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logstash_scribbler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Elliot Hursh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # LogstashScribbler
2
+
3
+ Easily add Logstash support for Scribbler logs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'logstash_scribbler'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install logstash_scribbler
20
+
21
+ ## Usage
22
+
23
+ require 'logstash_scribbler' and then add the following line to your scribbler initializer.
24
+ ```ruby
25
+ config.template = LogstashScribbler.template
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/[my-github-username]/logstash_scribbler/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,44 @@
1
+ module LogstashScribbler
2
+ class Message
3
+ attr_reader :error, :message, :custom_fields, :object
4
+ def initialize(options)
5
+ @error = inspected_error(options[:error])
6
+ @message = options[:message]
7
+ @custom_fields = options[:custom_fields]
8
+ @object = options[:object]
9
+ end
10
+
11
+ def log
12
+ LogStash::Event.new(data).to_json
13
+ end
14
+
15
+ def data
16
+ log_msg = {
17
+ :error => error,
18
+ :message => message,
19
+ }
20
+ log_msg = custom_fields.merge!(log_msg) if custom_fields
21
+ log_msg = namespaced_object.merge!(log_msg) if object
22
+ log_msg.reject { |k, v| v.nil? }
23
+ end
24
+
25
+ def namespaced_object
26
+ return { :object => object } unless is_active_record?(object)
27
+ object_type = object.class.name
28
+ {object_type.to_sym => object}
29
+ end
30
+
31
+ def inspected_error(error)
32
+ if error.is_a? Exception
33
+ e = error
34
+ error = {:message => e.message, :inspect => e.inspect, :backtrace => e.backtrace}
35
+ else
36
+ error
37
+ end
38
+ end
39
+
40
+ def is_active_record?(object)
41
+ object.is_a?(ActiveRecord::Base)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module LogstashScribbler
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,18 @@
1
+ require "logstash_scribbler/version"
2
+ require "logstash_scribbler/message"
3
+
4
+ module LogstashScribbler
5
+ def self.template
6
+ lambda do |options|
7
+ load_dependencies
8
+ LogstashScribbler::Message.new(options).log
9
+ end
10
+ end
11
+
12
+ def self.load_dependencies
13
+ require 'logstash-event'
14
+ rescue LoadError
15
+ puts 'You need to install the logstash-event gem to use the logstash output.'
16
+ raise
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logstash_scribbler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logstash_scribbler"
8
+ spec.version = LogstashScribbler::VERSION
9
+ spec.authors = ["Elliot Hursh"]
10
+ spec.email = ["elliothursh@gmail.com"]
11
+ spec.summary = %q{Creates a logstash template for logstash}
12
+ spec.description = %q{Creates a logstash template for logstash}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "logstash-event"
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "activerecord"
25
+ spec.add_development_dependency "activesupport"
26
+ spec.add_development_dependency "rspec"
27
+ end
data/spec/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,85 @@
1
+ require "spec_helper"
2
+ # require "active_record/core"
3
+ require "logstash_scribbler/message"
4
+
5
+ module LogstashScribbler
6
+ describe Message do
7
+ let(:message) {LogstashScribbler::Message.new({:error => "Something Bad", :message => nil, :object => [1,2,3]})}
8
+ before do
9
+ allow(message).to receive(:is_active_record?).and_return(false)
10
+ end
11
+
12
+ context "#log" do
13
+ require 'logstash-event'
14
+ it "should call Logtash::Event new" do
15
+ expect(LogStash::Event).to receive(:new).once
16
+ message.log
17
+ end
18
+ end
19
+
20
+ context "#data" do
21
+ it "should not return nil values" do
22
+ expect(message.data).to eq({:error => "Something Bad", :object => [1,2,3]})
23
+ end
24
+
25
+ it "calls #namespaced_object when passed on object" do
26
+ expect(message).to receive(:namespaced_object).and_return({:object => [1,2,3]})
27
+ message.data
28
+ end
29
+
30
+ it "puts custom fields at top level" do
31
+ options = {:error => "Something Bad", :custom_fields => {:name => "Sport Ngin", :error => "Something kind of Bad"}}
32
+ message = LogstashScribbler::Message.new(options)
33
+ expect(options[:custom_fields][:name]).to eq(message.data[:name])
34
+ expect(options[:error]).to eq(message.data[:error])
35
+ end
36
+
37
+ it "keeps attribute precedence ((:error || :message) > :custom_fields > :object))" do
38
+ options = {:message => "Normal Message", :custom_fields => { :message => "Custom Message", :object => [1]}, :object => [3,4,5]}
39
+ message = LogstashScribbler::Message.new(options)
40
+ allow(message).to receive(:is_active_record?).and_return(false)
41
+ expect(message.data).to eq({ :message => "Normal Message", :object => [1] })
42
+ end
43
+ end
44
+
45
+ context "#namespaced_object" do
46
+ context "when passed non ActiveRecord::Base object" do
47
+ it "returns a hash" do
48
+ expect(message.namespaced_object).to be_a(Hash)
49
+ end
50
+ it "places object under the 'object' key" do
51
+ expect(message.namespaced_object[:object]).to eq([1,2,3])
52
+ end
53
+ end
54
+
55
+ context "when passed ActiveRecord::Base object" do
56
+ before do
57
+ allow(message).to receive(:is_active_record?).and_return(true)
58
+ end
59
+ it "creates hash from object" do
60
+ expect(message.namespaced_object).to be_a(Hash)
61
+ end
62
+ it "prepends class name to instance variable names" do
63
+ expect(message.namespaced_object.has_key?(:Array)).to eq(true)
64
+ end
65
+ end
66
+ end
67
+
68
+ context "#inspected_error" do
69
+ context "when passed non Exception" do
70
+ it "returns error" do
71
+ expect(message.error).to eq("Something Bad")
72
+ end
73
+ end
74
+
75
+ context "when passed Exception" do
76
+ error = Exception.new
77
+ message = LogstashScribbler::Message.new({:error => error})
78
+ it "returns a hash of the exception" do
79
+ expect(message.error).to be_a(Hash)
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+ require "logstash_scribbler"
3
+
4
+ describe LogstashScribbler do
5
+ let(:options) do
6
+ {:message => "FooFoo Bar"}
7
+ end
8
+ let(:message) {LogstashScribbler::Message.new(options)}
9
+
10
+ context ".template" do
11
+ it "returns a lambda" do
12
+ expect(LogstashScribbler.template).to be_a(Proc)
13
+ end
14
+ end
15
+
16
+ it "calls log" do
17
+ allow(LogstashScribbler::Message).to receive(:new).and_return(message)
18
+ expect(message).to receive(:log).once
19
+ LogstashScribbler.template.call({:message => "FooFoo Bar"})
20
+ end
21
+
22
+ it "calls .load_dependencies" do
23
+ expect(LogstashScribbler).to receive(:load_dependencies).once
24
+ LogstashScribbler.template.call({:message => "FooFoo Bar"})
25
+ end
26
+
27
+
28
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ # config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+
91
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash_scribbler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Elliot Hursh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-event
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Creates a logstash template for logstash
98
+ email:
99
+ - elliothursh@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".octopolo.yml"
106
+ - ".rspec"
107
+ - ".soyuz.yml"
108
+ - ".travis.yml"
109
+ - CHANGELOG.markdown
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/logstash_scribbler.rb
115
+ - lib/logstash_scribbler/message.rb
116
+ - lib/logstash_scribbler/version.rb
117
+ - logstash_scribbler.gemspec
118
+ - spec/.DS_Store
119
+ - spec/logstash_scribbler/.DS_Store
120
+ - spec/logstash_scribbler/message_spec.rb
121
+ - spec/logstash_scribbler_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: ''
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Creates a logstash template for logstash
147
+ test_files:
148
+ - spec/.DS_Store
149
+ - spec/logstash_scribbler/.DS_Store
150
+ - spec/logstash_scribbler/message_spec.rb
151
+ - spec/logstash_scribbler_spec.rb
152
+ - spec/spec_helper.rb