yell-adapters-fluentd 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+ gem "yell", "~> 2.0"
3
+ gem "fluent-logger", "~> 0.4.3"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.8.0"
7
+ gem "rr"
8
+ gem "simplecov"
9
+
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 1.8.7"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.5)
5
+ builder (3.2.2)
6
+ diff-lcs (1.1.3)
7
+ docile (1.1.1)
8
+ faraday (0.8.8)
9
+ multipart-post (~> 1.2.0)
10
+ fluent-logger (0.4.7)
11
+ msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
12
+ yajl-ruby (~> 1.0)
13
+ git (1.2.6)
14
+ github_api (0.10.1)
15
+ addressable
16
+ faraday (~> 0.8.1)
17
+ hashie (>= 1.2)
18
+ multi_json (~> 1.4)
19
+ nokogiri (~> 1.5.2)
20
+ oauth2
21
+ hashie (2.0.5)
22
+ highline (1.6.20)
23
+ httpauth (0.2.0)
24
+ jeweler (1.8.8)
25
+ builder
26
+ bundler (~> 1.0)
27
+ git (>= 1.2.5)
28
+ github_api (= 0.10.1)
29
+ highline (>= 1.6.15)
30
+ nokogiri (= 1.5.10)
31
+ rake
32
+ rdoc
33
+ json (1.8.1)
34
+ jwt (0.1.8)
35
+ multi_json (>= 1.5)
36
+ msgpack (0.5.8)
37
+ multi_json (1.8.2)
38
+ multi_xml (0.5.5)
39
+ multipart-post (1.2.0)
40
+ nokogiri (1.5.10)
41
+ oauth2 (0.9.2)
42
+ faraday (~> 0.8)
43
+ httpauth (~> 0.2)
44
+ jwt (~> 0.1.4)
45
+ multi_json (~> 1.0)
46
+ multi_xml (~> 0.5)
47
+ rack (~> 1.2)
48
+ rack (1.5.2)
49
+ rake (10.1.1)
50
+ rdoc (3.12.2)
51
+ json (~> 1.4)
52
+ rr (1.1.2)
53
+ rspec (2.8.0)
54
+ rspec-core (~> 2.8.0)
55
+ rspec-expectations (~> 2.8.0)
56
+ rspec-mocks (~> 2.8.0)
57
+ rspec-core (2.8.0)
58
+ rspec-expectations (2.8.0)
59
+ diff-lcs (~> 1.1.2)
60
+ rspec-mocks (2.8.0)
61
+ simplecov (0.8.2)
62
+ docile (~> 1.1.0)
63
+ multi_json
64
+ simplecov-html (~> 0.8.0)
65
+ simplecov-html (0.8.0)
66
+ yajl-ruby (1.2.0)
67
+ yell (2.0.1)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ bundler (~> 1.0)
74
+ fluent-logger (~> 0.4.3)
75
+ jeweler (~> 1.8.7)
76
+ rdoc (~> 3.12)
77
+ rr
78
+ rspec (~> 2.8.0)
79
+ simplecov
80
+ yell (~> 2.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Jason Smith
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ Fluentd adapter for Yell
2
+
3
+ If you are not yet familiar with **Yell - Your Extensible Logging Library**
4
+ check out the github project under https://github.com/rudionrails/yell or jump
5
+ directly into the Yell wiki at https://github.com/rudionrails/yell/wiki.
6
+
7
+ ## Installation
8
+
9
+ System wide:
10
+
11
+ ```console
12
+ gem install yell-adapters-fluentd```
13
+
14
+ Or in your Gemfile:
15
+
16
+ ```ruby
17
+ gem "yell-adapters-fluentd"
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ The Fluentd adapter is based on the GELF adapter at https://github.com/rudionrails/yell-adapters-gelf
23
+
24
+ ```ruby
25
+ logger = Yell.new :fluentd
26
+
27
+ # or alternatively with the block syntax
28
+ logger = Yell.new do |l|
29
+ l.adapter :fluentd
30
+ end
31
+
32
+ logger.info 'Hello World!'
33
+ ```
34
+
35
+ By default, the adapter will send the following information to Fluentd:
36
+
37
+ `level`: The current log level
38
+ `timestamp`: The time when the log event occured
39
+ `host`: The current hostname
40
+ `file`: The name of the file where the log event occured
41
+ `line`: The line in the file where the log event occured
42
+ `_method`: The method where the log event occured
43
+ `_pid`: The PID of your current process
44
+
45
+ ### Example: Running Fluentd on a different host or port
46
+
47
+ ```ruby
48
+ logger = Yell.new :fluentd, :host => '127.0.0.1', :port => 1234
49
+
50
+ # or with the block syntax
51
+ logger = Yell.new do |l|
52
+ l.adapter :fluentd, :host => '127.0.0.1', :port => 1234
53
+ end
54
+
55
+ logger.info 'Hello World!'
56
+ ```
57
+
58
+ ### Example: Using a custom tag
59
+ By default, the tag "yell" is used. This can be overridden for custom handling.
60
+
61
+ ```ruby
62
+ logger = Yell.new :fluentd, :tag => 'yell.custom'
63
+
64
+ # or with the block syntax
65
+ logger = Yell.new do |l|
66
+ l.adapter :fluentd, :tag => 'yell.custom'
67
+ end
68
+
69
+ logger.info 'Hello World!'
70
+ ```
71
+
72
+ ### Example: Passing additional keys to the adapter
73
+
74
+ ```ruby
75
+ logger = Yell.new :fluentd
76
+
77
+ logger.info "Hello World", "_thread_id" => Thread.current.object_id,
78
+ "_current_user_id" => current_user.id
79
+ ```
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "yell-adapters-fluentd"
18
+ gem.homepage = "http://github.com/red5studios/yell-adapters-fluentd"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Fluentd adapter for Yell}
21
+ gem.description = %Q{Fluentd adapter for Yell}
22
+ gem.email = "jsmith@red5studios.com"
23
+ gem.authors = ["Jason Smith"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "yell-adapters-fluentd #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/yell/adapters/fluentd'
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'yell'
3
+ require 'fluent-logger'
4
+
5
+ module Yell
6
+ module Adapters
7
+ class Fluentd < Yell::Adapters::Base
8
+
9
+ attr_accessor :tag, :host, :port
10
+ attr_accessor :log
11
+
12
+ setup do |options|
13
+ @host = (options[:host] || 'localhost')
14
+ @port = (options[:port] || 24224)
15
+ @tag = (options[:tag] || "yell")
16
+
17
+ connect
18
+ end
19
+
20
+ close do
21
+ @log.close if @log
22
+ end
23
+
24
+ write do |event|
25
+ connect
26
+
27
+ message = format({
28
+ 'version' => '1.0',
29
+ 'level' => Severities[event.level],
30
+ 'timestamp' => event.time.to_f,
31
+ 'host' => event.hostname,
32
+ 'file' => event.file,
33
+ 'line' => event.line,
34
+ '_method' => event.method,
35
+ '_pid' => event.pid
36
+ }, *event.messages )
37
+
38
+ log.post(tag, message)
39
+ end
40
+
41
+ def connect
42
+ @log ||= Fluent::Logger::FluentLogger.new(nil, :host => (@host || 'localhost'), :port => (@port || 24224))
43
+ end
44
+
45
+ def format( *messages )
46
+ messages.inject(Hash.new) do |result, m|
47
+ result.merge to_message(m)
48
+ end
49
+ end
50
+
51
+ def to_message( message )
52
+ case message
53
+ when Hash
54
+ message
55
+ when Exception
56
+ { "short_message" => "#{message.class}: #{message.message}" }.tap do |m|
57
+ m.merge!( "long_message" => message.backtrace.join("\n") ) if message.backtrace
58
+ end
59
+ else { "short_message" => message.to_s }
60
+ end
61
+ end
62
+ end
63
+
64
+ register(:fluentd, Yell::Adapters::Fluentd)
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rr'
5
+ require 'yell-adapters-fluentd'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.mock_framework = :rr
13
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yell::Adapters::Fluentd do
4
+
5
+ class FluentStub
6
+ def tag; @tag; end
7
+ def message; @message; end
8
+
9
+ def post(tag,message)
10
+ @tag = tag
11
+ @message = message
12
+ end
13
+ end
14
+
15
+ let(:logger) { Yell::Logger.new }
16
+
17
+ context "a new Yell::Adapters::Fluentd instance" do
18
+ subject { Yell::Adapters::Fluentd.new }
19
+
20
+ its(:host) { should == 'localhost' }
21
+ its(:port) { should == 24224 }
22
+ its(:tag) { should == 'yell' }
23
+ end
24
+
25
+ context :host do
26
+ let(:adapter) { Yell::Adapters::Fluentd.new }
27
+ subject { adapter.host }
28
+
29
+ before { adapter.host = 'hostname' }
30
+
31
+ it { should == 'hostname' }
32
+ end
33
+
34
+ context :port do
35
+ let(:adapter) { Yell::Adapters::Fluentd.new }
36
+ subject { adapter.port }
37
+
38
+ before { adapter.port = 1234 }
39
+
40
+ it { should == 1234 }
41
+ end
42
+
43
+ context :write do
44
+ let(:event) { Yell::Event.new(logger, 1, 'Hello World') }
45
+ let(:adapter) { Yell::Adapters::Fluentd.new }
46
+
47
+ context :datagrams do
48
+ before do
49
+ @fluent = FluentStub.new
50
+ stub(Fluent::Logger::FluentLogger).new(nil,anything) { @fluent }
51
+ end
52
+
53
+ after { adapter.write event }
54
+
55
+ it "should receive :version" do
56
+ mock.proxy(@fluent).post("yell",hash_including('version' => '1.0'))
57
+ end
58
+
59
+ it "should receive :level" do
60
+ mock.proxy(@fluent).post("yell", hash_including('level' => Yell::Severities[event.level]) )
61
+ end
62
+
63
+ it "should receive :short_message" do
64
+ mock.proxy(@fluent).post("yell", hash_including('short_message' => event.messages.first) )
65
+ end
66
+
67
+ it "should receive :timestamp" do
68
+ mock.proxy(@fluent).post("yell", hash_including('timestamp' => event.time.to_f) )
69
+ end
70
+
71
+ it "should receive :host" do
72
+ mock.proxy(@fluent).post("yell", hash_including('host' => event.hostname) )
73
+ end
74
+
75
+ it "should receive :file" do
76
+ mock.proxy(@fluent).post("yell", hash_including('file' => event.file) )
77
+ end
78
+
79
+ it "should receive :line" do
80
+ mock.proxy(@fluent).post("yell", hash_including('line' => event.line) )
81
+ end
82
+
83
+ it "should receive :method" do
84
+ mock.proxy(@fluent).post("yell", hash_including('_method' => event.method) )
85
+ end
86
+
87
+ it "should receive :pid" do
88
+ mock.proxy(@fluent).post("yell", hash_including('_pid' => event.pid) )
89
+ end
90
+
91
+ context "given a Hash" do
92
+ let(:event) { Yell::Event.new(logger, 1, 'short_message' => 'Hello World', '_custom_field' => 'Custom Field') }
93
+
94
+ it "should receive :short_message" do
95
+ mock.proxy(@fluent).post("yell", hash_including('short_message' => 'Hello World') )
96
+ end
97
+
98
+ it "should receive :_custom_field" do
99
+ mock.proxy(@fluent).post("yell", hash_including('_custom_field' => 'Custom Field') )
100
+ end
101
+ end
102
+
103
+ context "given an Exception" do
104
+ let(:exception) { StandardError.new('This is an error') }
105
+ let(:event) { Yell::Event.new(logger, 1, exception) }
106
+
107
+ before do
108
+ mock(exception).backtrace.times(any_times) { [:back, :trace] }
109
+ end
110
+
111
+ it "should receive :short_message" do
112
+ mock.proxy(@fluent).post("yell", hash_including('short_message' => "#{exception.class}: #{exception.message}") )
113
+ end
114
+
115
+ it "should receive :long_message" do
116
+ mock.proxy(@fluent).post("yell", hash_including('long_message' => "back\ntrace") )
117
+ end
118
+ end
119
+
120
+ context "given a Yell::Event with :options" do
121
+ let(:event) { Yell::Event.new(logger, 1, 'Hello World', "_custom_field" => 'Custom Field') }
122
+
123
+ it "should receive :short_message" do
124
+ mock.proxy(@fluent).post("yell", hash_including('short_message' => 'Hello World') )
125
+ end
126
+
127
+ it "should receive :_custom_field" do
128
+ mock.proxy(@fluent).post("yell", hash_including('_custom_field' => 'Custom Field') )
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yell-adapters-fluentd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yell
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluent-logger
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.4.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.8.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rdoc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '3.12'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '3.12'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.8.7
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.8.7
142
+ description: Fluentd adapter for Yell
143
+ email: jsmith@red5studios.com
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files:
147
+ - LICENSE.txt
148
+ - README.md
149
+ files:
150
+ - .document
151
+ - .rspec
152
+ - Gemfile
153
+ - Gemfile.lock
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - VERSION
158
+ - lib/yell-adapters-fluentd.rb
159
+ - lib/yell/adapters/fluentd.rb
160
+ - spec/spec_helper.rb
161
+ - spec/yell/adapters/fluentd_spec.rb
162
+ homepage: http://github.com/red5studios/yell-adapters-fluentd
163
+ licenses:
164
+ - MIT
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ segments:
176
+ - 0
177
+ hash: 2881317609981975877
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.25
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Fluentd adapter for Yell
190
+ test_files: []