exception_notification-fluent_logger_notifier 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/exception_notification-fluent_logger_notifier.gemspec +25 -0
- data/lib/exception_notification_fluent_logger_notifier.rb +1 -0
- data/lib/exception_notifier/fluent_logger_notifier.rb +75 -0
- data/lib/exception_notifier/fluent_logger_notifier/version.rb +5 -0
- data/spec/exception_notifier/fluent_logger_notifier_spec.rb +107 -0
- data/spec/spec_helper.rb +2 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15f0d4a9779623de33ccda317f06e98b20295a72
|
4
|
+
data.tar.gz: eb6291516242f63432c9d9a16d863b9515f29d15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d5b6d9715ac0685adc21cc7f01245d2af0324a7c5c0c6a9a70a58ebf508174e6f632cdb4b00c83769b64c4a567df3259576023a8039638d74df272fe5dbffb1
|
7
|
+
data.tar.gz: 8988a3954288fc31ec9f744d683b55a5fe7744e8ca028e971fdbc26fcc47760bbed7317bea89e527740876708182cb298769a9f2b83eabde6cd1f2060ffea4f3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# ExceptionNotifier::FluentLoggerNotifier
|
2
|
+
|
3
|
+
`ExceptionNotifier::FluentLoggerNotifier` is a custom notifier for [ExceptionNotification](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
|
+
|
24
|
+
* Key `tag_prefix` is for the fluentd tag.
|
25
|
+
* Key `template` is for setting log format and must be Hash.
|
26
|
+
* Key `logger_settings` is for settings of the logger instance.
|
27
|
+
* If key `test_logger` is `true`, the notifier uses `Fluent::Logger::TestLogger` instead of `FluentLogger`.
|
28
|
+
|
29
|
+
See also [exception\_notifier's doc](http://smartinez87.github.io/exception_notification/#notifiers).
|
30
|
+
|
31
|
+
### Example
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
|
35
|
+
fluent_logger: {
|
36
|
+
tag_prefix: "exceptions",
|
37
|
+
logger_settings: {
|
38
|
+
host: "localhost",
|
39
|
+
port: 8888,
|
40
|
+
}
|
41
|
+
template: {
|
42
|
+
exception_class: ->(exception, options) { exception.class_name },
|
43
|
+
exception_message: => -> (exception, options) { exception.messaage },
|
44
|
+
}
|
45
|
+
}
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
[MIT](http://makimoto.mit-license.org/)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "exception_notifier/fluent_logger_notifier/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "exception_notification-fluent_logger_notifier"
|
7
|
+
spec.version = ExceptionNotifier::FluentLoggerNotifier::VERSION
|
8
|
+
spec.authors = ["Shimpei Makimoto"]
|
9
|
+
spec.email = ["makimoto@tsuyabu.in"]
|
10
|
+
spec.summary = %q{A custom notifier for ExceptionNotification which notifies exceptions to Fluentd via fluent-logger}
|
11
|
+
spec.homepage = "https://github.com/makimoto/exception_notification-fluent_logger_notifier"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "pry"
|
23
|
+
spec.add_dependency "exception_notification", "~> 4.0.1"
|
24
|
+
spec.add_dependency "fluent-logger"
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "exception_notifier/fluent_logger_notifier"
|
@@ -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,107 @@
|
|
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
|
+
logger_settings: {
|
14
|
+
:host => "localhost",
|
15
|
+
:port => 8888,
|
16
|
+
},
|
17
|
+
template: {
|
18
|
+
message: ->(exception, options) { "Exception: #{exception.class}: #{exception.message}" }
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#call" do
|
24
|
+
it "logs valid data" do
|
25
|
+
notifier.call(FooException.new("bar message"))
|
26
|
+
notifier.logger.queue.last.should == { message: "Exception: FooException: bar message" }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ExceptionNotifier::FluentLoggerNotifier::Argument do
|
31
|
+
subject do
|
32
|
+
ExceptionNotifier::FluentLoggerNotifier::Argument.build(template, exception, {})
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with String" do
|
36
|
+
let(:template) do
|
37
|
+
"string"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns string without any change" do
|
41
|
+
should == "string"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with Proc" do
|
46
|
+
let(:template) do
|
47
|
+
->(e, opts) { "Exception: #{e.class}: #{e.message}" }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns intended string" do
|
51
|
+
should == "Exception: FooException: bar message"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with Hash" do
|
56
|
+
let(:template) do
|
57
|
+
{
|
58
|
+
class_name: ->(e, opts) { e.class.to_s },
|
59
|
+
message: ->(e, opts) { e.message},
|
60
|
+
baz: 42,
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns intended hash" do
|
65
|
+
should == { class_name: "FooException", message: "bar message", baz: 42 }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with Array" do
|
70
|
+
let(:template) do
|
71
|
+
[
|
72
|
+
->(e, opts) { 1 + 42 },
|
73
|
+
->(e, opts) { e.class.to_s },
|
74
|
+
nil,
|
75
|
+
]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns intended array" do
|
79
|
+
[43, "FooException", nil]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with nested templates" do
|
84
|
+
let(:template) do
|
85
|
+
{
|
86
|
+
string: "string",
|
87
|
+
int: 42,
|
88
|
+
hash: {
|
89
|
+
proc: ->(e, opts) { e.class.to_s }
|
90
|
+
},
|
91
|
+
array: [42, ->(e, opts) { e.message }],
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns intended value" do
|
96
|
+
{
|
97
|
+
string: "string",
|
98
|
+
int: 42,
|
99
|
+
hash: {
|
100
|
+
proc: "FooException",
|
101
|
+
},
|
102
|
+
array: [42, "bar message"],
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception_notification-fluent_logger_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shimpei Makimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-03 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_notification_fluent_logger_notifier.rb
|
111
|
+
- lib/exception_notifier/fluent_logger_notifier.rb
|
112
|
+
- lib/exception_notifier/fluent_logger_notifier/version.rb
|
113
|
+
- spec/exception_notifier/fluent_logger_notifier_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: https://github.com/makimoto/exception_notification-fluent_logger_notifier
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.5.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A custom notifier for ExceptionNotification which notifies exceptions to
|
139
|
+
Fluentd via fluent-logger
|
140
|
+
test_files:
|
141
|
+
- spec/exception_notifier/fluent_logger_notifier_spec.rb
|
142
|
+
- spec/spec_helper.rb
|