exception_notification_fluent_logger_notifier 0.0.1

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: 363a52b9c8d29322704c1d5cd8e6c7cbc3ccafed
4
+ data.tar.gz: a87c47d897df2017fd4428a30e833b13a5d6e10a
5
+ SHA512:
6
+ metadata.gz: ee98d34470035e43addfe6947f899c3294476f6f7626e1d4ce7f67346e90ca242977ea1e6c22cd35f575c4864ae795c47c6f86f2a090e71d586cf584a28096ad
7
+ data.tar.gz: e0279bd1116b5a8dfca6d04459d537ada043ec1ceacb0d50d83d48f3c74fb94773185e452499f983259d36123a9c8fe84f826519bab5b9ad17550f29ec6f277d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in exception_notification_fluent_logger_notifier.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ExceptionNotifier::FluentLoggerNotifier
2
+
3
+ `ExceptionNotifier::FluentLoggerNotifier` is a custom notifier for [ExceptionNotifier](http://smartinez87.github.io/exception_notification/).
4
+ It sends exception notifications to [Fluentd data collector](http://fluentd.org/) via [fluent-logger](https://github.com/fluent/fluent-logger-ruby).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'exception_notification_fluent_logger_notifier'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install exception_notification_fluent_logger_notifier
19
+
20
+ ## Usage
21
+
22
+ As other exception notifiers, add settings at the environments.
23
+ Key `tag_prefix` is for the fluentd tag.
24
+ Key `templete` is for setting log format and must be Hash.
25
+
26
+ See also [exception_notifier's doc](http://smartinez87.github.io/exception_notification/#notifiers).
27
+
28
+ ### Example
29
+
30
+ ```ruby
31
+ Whatever::Application.config.middleware.use ExceptionNotification::Rack,
32
+ :fluent_logger => {
33
+ :tag_prefix => "exceptions",
34
+ :templete => {
35
+ exception_class: ->(exception, options) { exception.class_name },
36
+ exception_message: -> (exception, options) { exception.messaage },
37
+ }
38
+ }
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+ ## License
50
+
51
+ [MIT](http://makimoto.mit-license.org/)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "exception_notifier/fluent_logger_notifier/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "exception_notification_fluent_logger_notifier"
8
+ spec.version = ExceptionNotifier::FluentLoggerNotifier::VERSION
9
+ spec.authors = ["Shimpei Makimoto"]
10
+ spec.email = ["makimoto@tsuyabu.in"]
11
+ spec.summary = %q{A custom notifier for ExceptionNotification which notifies exceptions to Fluentd via fluent-logger}
12
+ spec.homepage = "https://github.com/makimoto/exception_notification_fluent_logger_notifier"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_dependency "exception_notification", "~> 4.0.1"
25
+ spec.add_dependency "fluent-logger"
26
+ end
@@ -0,0 +1,5 @@
1
+ module ExceptionNotifier
2
+ class FluentLoggerNotifier
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,75 @@
1
+ require "fluent-logger"
2
+ module ExceptionNotifier
3
+ class FluentLoggerNotifier
4
+
5
+ attr_accessor :logger, :template
6
+ class ConfigurationError < Exception;end
7
+
8
+ def initialize(options)
9
+ @template = options.delete(:template)
10
+ raise ConfigurationError, "`template` key must be set" unless @template
11
+
12
+ logger_settings = options.delete(:logger_settings) || {}
13
+ if options.delete(:test_logger)
14
+ @logger = Fluent::Logger::TestLogger.new
15
+ else
16
+ tag_prefix = options.delete(:tag_prefix)
17
+ @logger = Fluent::Logger::FluentLogger.new(tag_prefix, logger_settings)
18
+ end
19
+ end
20
+
21
+ def call(exception, options={})
22
+ arg = Argument.build(template, exception, options)
23
+ logger.post(nil, arg)
24
+ end
25
+
26
+ class SetupError < Exception;end
27
+
28
+ class Argument
29
+ def initialize(template, exception, options = {})
30
+ @exception = exception
31
+ @options = options
32
+ @template = template
33
+ end
34
+
35
+ def build
36
+ expand_object(@template)
37
+ end
38
+
39
+ def self.build(template, exception, options = {})
40
+ self.new(template, exception, options).build
41
+ end
42
+
43
+ private
44
+
45
+ def expand_object(obj)
46
+ case obj
47
+ when Hash
48
+ expand_hash(obj)
49
+ when Array
50
+ expand_array(obj)
51
+ when Proc
52
+ expand_proc(obj)
53
+ else
54
+ obj
55
+ end
56
+ end
57
+
58
+ def expand_proc(prok)
59
+ expand_object(prok.call(@exception, @options))
60
+ end
61
+
62
+ def expand_array(array)
63
+ array.map {|element| expand_object(element) }
64
+ end
65
+
66
+ def expand_hash(hash)
67
+ {}.tap do |result|
68
+ hash.each do |k, v|
69
+ result[k] = expand_object(v)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,103 @@
1
+ require "spec_helper"
2
+
3
+ describe ExceptionNotifier::FluentLoggerNotifier do
4
+ class FooException < Exception;end
5
+
6
+ let(:exception) do
7
+ FooException.new("bar message")
8
+ end
9
+
10
+ let(:notifier) do
11
+ ExceptionNotifier::FluentLoggerNotifier.new(
12
+ test_logger: true,
13
+ template: {
14
+ message: ->(exception, options) { "Exception: #{exception.class}: #{exception.message}" }
15
+ }
16
+ )
17
+ end
18
+
19
+ describe "#call" do
20
+ it "logs valid data" do
21
+ notifier.call(FooException.new("bar message"))
22
+ notifier.logger.queue.last.should == { message: "Exception: FooException: bar message" }
23
+ end
24
+ end
25
+
26
+ describe ExceptionNotifier::FluentLoggerNotifier::Argument do
27
+ subject do
28
+ ExceptionNotifier::FluentLoggerNotifier::Argument.build(template, exception, {})
29
+ end
30
+
31
+ context "with String" do
32
+ let(:template) do
33
+ "string"
34
+ end
35
+
36
+ it "returns string without any change" do
37
+ should == "string"
38
+ end
39
+ end
40
+
41
+ context "with Proc" do
42
+ let(:template) do
43
+ ->(e, opts) { "Exception: #{e.class}: #{e.message}" }
44
+ end
45
+
46
+ it "returns intended string" do
47
+ should == "Exception: FooException: bar message"
48
+ end
49
+ end
50
+
51
+ context "with Hash" do
52
+ let(:template) do
53
+ {
54
+ class_name: ->(e, opts) { e.class.to_s },
55
+ message: ->(e, opts) { e.message},
56
+ baz: 42,
57
+ }
58
+ end
59
+
60
+ it "returns intended hash" do
61
+ should == { class_name: "FooException", message: "bar message", baz: 42 }
62
+ end
63
+ end
64
+
65
+ context "with Array" do
66
+ let(:template) do
67
+ [
68
+ ->(e, opts) { 1 + 42 },
69
+ ->(e, opts) { e.class.to_s },
70
+ nil,
71
+ ]
72
+ end
73
+
74
+ it "returns intended array" do
75
+ [43, "FooException", nil]
76
+ end
77
+ end
78
+
79
+ context "with nested templates" do
80
+ let(:template) do
81
+ {
82
+ string: "string",
83
+ int: 42,
84
+ hash: {
85
+ proc: ->(e, opts) { e.class.to_s }
86
+ },
87
+ array: [42, ->(e, opts) { e.message }],
88
+ }
89
+ end
90
+
91
+ it "returns intended value" do
92
+ {
93
+ string: "string",
94
+ int: 42,
95
+ hash: {
96
+ proc: "FooException",
97
+ },
98
+ array: [42, "bar message"],
99
+ }
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,2 @@
1
+ require "fluent-logger"
2
+ require "exception_notifier/fluent_logger_notifier"
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exception_notification_fluent_logger_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shimpei Makimoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: exception_notification
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 4.0.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: fluent-logger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - makimoto@tsuyabu.in
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - exception_notification_fluent_logger_notifier.gemspec
110
+ - lib/exception_notifier/fluent_logger_notifier.rb
111
+ - lib/exception_notifier/fluent_logger_notifier/version.rb
112
+ - spec/exception_notifier/fluent_logger_notifier_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: https://github.com/makimoto/exception_notification_fluent_logger_notifier
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A custom notifier for ExceptionNotification which notifies exceptions to
138
+ Fluentd via fluent-logger
139
+ test_files:
140
+ - spec/exception_notifier/fluent_logger_notifier_spec.rb
141
+ - spec/spec_helper.rb