fluent-logger 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ebb952132e3bf5135cccf95edb35c73e15faa33
4
- data.tar.gz: 5cbeb4614a25258758ba62d0dbdf795ce9b41579
3
+ metadata.gz: b697bc01bf042c2ecafc345c71dd0c133d08519f
4
+ data.tar.gz: 490cf5426952cca33f6a6a98cd4d150ef2ddad43
5
5
  SHA512:
6
- metadata.gz: 092f6edfdc24d9561c9fa280c4dc9833c78fff5043f53c97c0f08e83f69a1d0875b317a9eba778394a45e6f6c3dbc3e399b28cce0a2e3990c42fa79e29ca4ba1
7
- data.tar.gz: d31116dab4915fb1c0817f1ac424c25b1ae85fe548f8a30eb4988cf9ca30359bee2fda9a7e499ec7a50720fc0a040ad4415b78e77b0e070ad65bc2d253dd5ca5
6
+ metadata.gz: d72fb3e957716c2003be82e669da0d14902631f98c710e32b530a5c099bbd56ec1e91e4cc392da55c00c0aaf11de08431682458e5ef32fbcaa6c78bda2efa371
7
+ data.tar.gz: 16783931f838a10cf82346f918faff6d8bab0f47172eaaf1bbc991a01549f2e704a3c45fa32f379b6133a481ca6b9b3a2b54793e473cbec321773df05d41944c
@@ -3,12 +3,29 @@ rvm:
3
3
  - 2.0.0
4
4
  - 2.1
5
5
  - 2.2
6
- - 2.3.0
7
- - rbx
6
+ - 2.3.1
7
+ - ruby-head
8
+
9
+ gemfile:
10
+ - Gemfile
11
+ - Gemfile.v0.12
8
12
 
9
13
  before_install: gem update bundler
10
14
  script: bundle exec rake spec
11
15
 
16
+ sudo: false
17
+
12
18
  matrix:
13
19
  allow_failures:
14
- - rvm: rbx
20
+ - rvm: ruby-head
21
+ exclude:
22
+ - rvm: 1.9.3
23
+ gemfile: Gemfile
24
+ - rvm: 2.0.0
25
+ gemfile: Gemfile
26
+ - rvm: 2.2
27
+ gemfile: Gemfile.v0.12
28
+ - rvm: 2.3.1
29
+ gemfile: Gemfile.v0.12
30
+ - rvm: ruby-head
31
+ gemfile: Gemfile.v0.12
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ Release 0.6.1 - 2016/11/02
2
+
3
+ * Add LevelFluentLogger: Standard Logger compatible interface
4
+
5
+ Release 0.6.0 - 2016/10/15
6
+
7
+ * Relax msgpack dependency
8
+ * ConsoleLogger: close io if io is stdout
9
+
1
10
  Release 0.5.1 - 2015/11/24
2
11
 
3
12
  * Allow injection of buffer overflow handler
data/Gemfile CHANGED
@@ -1,10 +1,11 @@
1
1
 
2
2
  source 'https://rubygems.org/'
3
3
 
4
+ gem "fluentd", :github => 'fluent/fluentd'
5
+
4
6
  gemspec
5
7
 
6
8
  gem "simplecov", :require => false
7
9
  gem "simplecov-vim"
8
10
 
9
- gem "fluentd"
10
11
  gem 'test-unit'
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'json', '= 1.8.3'
4
+ gem 'fluentd', '~> 0.12.0'
5
+
6
+ gemspec
data/README.md CHANGED
@@ -39,6 +39,63 @@ log.post("access", {"agent"=>"foo"})
39
39
  # output: myapp.access {"agent":"foo"}
40
40
  ```
41
41
 
42
+ ### Standard ::Logger compatible interface
43
+
44
+ #### Example1
45
+
46
+ ```ruby
47
+ require 'fluent-logger'
48
+ f = Fluent::Logger::LevelFluentLogger.new('fluent')
49
+
50
+ f.info("some application running.")
51
+ # output: fluent.info: {"level":"INFO","message":"some application running."}
52
+
53
+ f.warn("some application running.")
54
+ # output: fluent.warn: {"level":"WARN","message":"some application running."}
55
+ ```
56
+
57
+ #### Example2(add progname)
58
+
59
+ ```ruby
60
+ require 'fluent-logger'
61
+ f = Fluent::Logger::LevelFluentLogger.new('fluent')
62
+ f.info("some_application"){"some application running."}
63
+ # output: fluent.info: {"level":"INFO","message":"some application running.","progname":"some_application"}
64
+ ```
65
+
66
+ #### Example3(set log level)
67
+
68
+ ```ruby
69
+ require 'fluent-logger'
70
+ f = Fluent::Logger::LevelFluentLogger.new('fluent')
71
+ f.level = Logger::WARN
72
+ f.info("some_application"){"some application running."}
73
+ ```
74
+
75
+ Log level is ERROR so no output.
76
+
77
+ default log level is debug.
78
+
79
+
80
+ #### Example4(customize format for Rails)
81
+
82
+ ```ruby
83
+ require 'fluent-logger'
84
+ f = Fluent::Logger::LevelFluentLogger.new('fluent')
85
+
86
+ f.formatter = proc do |severity, datetime, progname, message|
87
+ map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
88
+ map[:message] = message if message
89
+ map[:progname] = progname if progname
90
+ map[:stage] = ENV['RAILS_ENV']
91
+ map[:service_name] = "SomeApp"
92
+ map
93
+ end
94
+
95
+ f.info("some_application"){"some application running."}
96
+ # output: fluent.info: {"level":"INFO","message":"some application running.","progname":"some_application","stage":"production","service_name":"SomeApp"}
97
+ ```
98
+
42
99
  ## Loggers
43
100
 
44
101
  ### Fluent
@@ -82,6 +139,8 @@ Fluent::Logger::FluentLogger.new(nil,
82
139
  :buffer_overflow_handler => handler)
83
140
  ```
84
141
 
142
+ ## Information
143
+
85
144
  |name|description|
86
145
  |---|---|
87
146
  |Web site|http://fluentd.org/|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -17,13 +17,14 @@
17
17
  #
18
18
  module Fluent
19
19
  module Logger
20
- autoload :ConsoleLogger , 'fluent/logger/console_logger'
21
- autoload :FluentLogger , 'fluent/logger/fluent_logger'
22
- autoload :LoggerBase , 'fluent/logger/logger_base'
23
- autoload :TestLogger , 'fluent/logger/test_logger'
24
- autoload :TextLogger , 'fluent/logger/text_logger'
25
- autoload :NullLogger , 'fluent/logger/null_logger'
26
- autoload :VERSION , 'fluent/logger/version'
20
+ autoload :ConsoleLogger , 'fluent/logger/console_logger'
21
+ autoload :FluentLogger , 'fluent/logger/fluent_logger'
22
+ autoload :LevelFluentLogger , 'fluent/logger/level_fluent_logger'
23
+ autoload :LoggerBase , 'fluent/logger/logger_base'
24
+ autoload :TestLogger , 'fluent/logger/test_logger'
25
+ autoload :TextLogger , 'fluent/logger/text_logger'
26
+ autoload :NullLogger , 'fluent/logger/null_logger'
27
+ autoload :VERSION , 'fluent/logger/version'
27
28
 
28
29
  @@default_logger = nil
29
30
 
@@ -0,0 +1,73 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'msgpack'
19
+ require 'socket'
20
+ require 'monitor'
21
+ require 'logger'
22
+ require 'json'
23
+
24
+ module Fluent
25
+ module Logger
26
+ class LevelFluentLogger < ::Logger
27
+
28
+ def initialize(tag_prefix = nil, *args)
29
+ @level = ::Logger::DEBUG
30
+ @default_formatter = proc do |severity, datetime, progname, message|
31
+ map = { level: format_severity(severity) }
32
+ map[:message] = message if message
33
+ map[:progname] = progname if progname
34
+ map
35
+ end
36
+ @fluent_logger = FluentLogger.new(tag_prefix, *args)
37
+ end
38
+
39
+ def add(severity, message = nil, progname = nil, &block)
40
+ severity ||= UNKNOWN
41
+ if severity < @level
42
+ return true
43
+ end
44
+ progname ||= @progname
45
+ if message.nil?
46
+ if block_given?
47
+ message = yield
48
+ else
49
+ message = progname
50
+ progname = @progname
51
+ end
52
+ end
53
+ map = format_message(severity, Time.now, progname, message)
54
+ @fluent_logger.post(format_severity(severity).downcase, map)
55
+ true
56
+ end
57
+
58
+ def close
59
+ @fluent_logger.close
60
+ end
61
+
62
+ def reopen
63
+ @fluent_logger.close
64
+ # we do not call #connect! here because 1) FluentLogger#connect! is not a public method
65
+ # 2) #post automatically connects if its connection is closed
66
+ end
67
+
68
+ def connect?
69
+ @fluent_logger.connect?
70
+ end
71
+ end
72
+ end
73
+ end
@@ -23,7 +23,7 @@ module Fluent
23
23
  end
24
24
 
25
25
  def post(tag, map)
26
- raise ArgumentError.new("Second argument should kind of Hash (tag: #{map})") unless map.kind_of? Hash
26
+ raise ArgumentError.new("Second argument must be a kind of Hash (#{tag}: #{map})") unless map.kind_of? Hash
27
27
  post_with_time(tag, map, Time.now)
28
28
  end
29
29
 
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Logger
3
3
 
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
 
6
6
  end
7
7
  end
@@ -1,31 +1,15 @@
1
1
 
2
2
  require 'spec_helper'
3
+ require 'support/dummy_serverengine'
4
+ require 'support/dummy_fluentd'
3
5
 
4
- require 'fluent/load'
5
- require 'fluent/test'
6
- require 'tempfile'
7
6
  require 'logger'
8
- require 'socket'
9
7
  require 'stringio'
10
8
  require 'fluent/logger/fluent_logger/cui'
11
- require 'plugin/out_test'
12
-
13
- $log = Fluent::Log.new(StringIO.new) # XXX should remove $log from fluentd
14
9
 
15
10
  describe Fluent::Logger::FluentLogger do
16
- WAIT = ENV['WAIT'] ? ENV['WAIT'].to_f : 0.1
17
-
18
- let(:fluentd_port) {
19
- port = 60001
20
- loop do
21
- begin
22
- TCPServer.open('localhost', port).close
23
- break
24
- rescue Errno::EADDRINUSE
25
- port += 1
26
- end
27
- end
28
- port
11
+ let(:fluentd) {
12
+ DummyFluentd.new
29
13
  }
30
14
 
31
15
  let(:logger) {
@@ -33,7 +17,7 @@ describe Fluent::Logger::FluentLogger do
33
17
  logger = ::Logger.new(@logger_io)
34
18
  Fluent::Logger::FluentLogger.new('logger-test', {
35
19
  :host => 'localhost',
36
- :port => fluentd_port,
20
+ :port => fluentd.port,
37
21
  :logger => logger,
38
22
  :buffer_overflow_handler => buffer_overflow_handler
39
23
  })
@@ -45,72 +29,38 @@ describe Fluent::Logger::FluentLogger do
45
29
  @logger_io
46
30
  }
47
31
 
48
- let(:output) {
49
- sleep 0.0001 # next tick
50
- if Fluent::Engine.respond_to?(:match)
51
- Fluent::Engine.match('logger-test').output
52
- else
53
- Fluent::Engine.root_agent.event_router.match('logger-test')
32
+ context "running fluentd" do
33
+ before(:all) do
34
+ @serverengine = DummyServerengine.new
35
+ @serverengine.startup
54
36
  end
55
- }
56
-
57
- let(:queue) {
58
- queue = []
59
- output.emits.each {|tag, time, record|
60
- queue << [tag, record]
61
- }
62
- queue
63
- }
64
37
 
65
- after(:each) do
66
- output.emits.clear rescue nil
67
- end
68
-
69
- def wait_transfer
70
- sleep WAIT
71
- end
72
-
73
- context "running fluentd" do
74
38
  before(:each) do
75
- @config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
76
- <source>
77
- type forward
78
- port #{fluentd_port}
79
- </source>
80
- <match logger-test.**>
81
- type test
82
- </match>
83
- EOF
84
- Fluent::Test.setup
85
- Fluent::Engine.run_configure(@config)
86
- @coolio_default_loop = nil
87
- @thread = Thread.new {
88
- @coolio_default_loop = Coolio::Loop.default
89
- Fluent::Engine.run
90
- }
91
- wait_transfer
39
+ fluentd.startup
92
40
  end
93
41
 
94
42
  after(:each) do
95
- @coolio_default_loop.stop
96
- Fluent::Engine.send :shutdown
97
- @thread.join
43
+ fluentd.shutdown
44
+ end
45
+
46
+ after(:all) do
47
+ @serverengine.shutdown
98
48
  end
99
49
 
100
50
  context('Post by CUI') do
101
51
  it('post') {
102
- args = %W(-h localhost -p #{fluentd_port} -t logger-test.tag -v a=b -v foo=bar)
52
+ args = %W(-h localhost -p #{fluentd.port} -t logger-test.tag -v a=b -v foo=bar)
103
53
  Fluent::Logger::FluentLogger::CUI.post(args)
104
- wait_transfer
105
- expect(queue.last).to eq ['logger-test.tag', {'a' => 'b', 'foo' => 'bar'}]
54
+ fluentd.wait_transfer
55
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'a' => 'b', 'foo' => 'bar'}]
106
56
  }
107
57
  end
108
58
 
109
59
  context('post') do
110
60
  it ('success') {
111
61
  expect(logger.post('tag', {'a' => 'b'})).to be true
112
- wait_transfer
113
- expect(queue.last).to eq ['logger-test.tag', {'a' => 'b'}]
62
+ fluentd.wait_transfer
63
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'a' => 'b'}]
114
64
  }
115
65
 
116
66
  it ('close after post') {
@@ -120,15 +70,15 @@ EOF
120
70
 
121
71
  logger.post('tag', {'b' => 'c'})
122
72
  expect(logger).to be_connect
123
- wait_transfer
124
- expect(queue.last).to eq ['logger-test.tag', {'b' => 'c'}]
73
+ fluentd.wait_transfer
74
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'b' => 'c'}]
125
75
  }
126
76
 
127
77
  it ('large data') {
128
78
  data = {'a' => ('b' * 1000000)}
129
79
  logger.post('tag', data)
130
- wait_transfer
131
- expect(queue.last).to eq ['logger-test.tag', data]
80
+ fluentd.wait_transfer
81
+ expect(fluentd.queue.last).to eq ['logger-test.tag', data]
132
82
  }
133
83
 
134
84
  it ('msgpack unsupport data') {
@@ -138,8 +88,8 @@ EOF
138
88
  'proc' => proc { 1 },
139
89
  }
140
90
  logger.post('tag', data)
141
- wait_transfer
142
- logger_data = queue.last.last
91
+ fluentd.wait_transfer
92
+ logger_data = fluentd.queue.last.last
143
93
  expect(logger_data['time']).to eq '2008-09-01 10:05:00 UTC'
144
94
  expect(logger_data['proc']).to be_truthy
145
95
  expect(logger_data['object']).to be_truthy
@@ -153,8 +103,8 @@ EOF
153
103
  'NaN' => (0.0/0.0) # JSON don't convert
154
104
  }
155
105
  logger.post('tag', data)
156
- wait_transfer
157
- expect(queue.last).to be_nil
106
+ fluentd.wait_transfer
107
+ expect(fluentd.queue.last).to be_nil
158
108
  logger_io.rewind
159
109
  logger_io.read =~ /FluentLogger: Can't convert to msgpack:/
160
110
  }
@@ -174,21 +124,21 @@ EOF
174
124
 
175
125
  context "initializer" do
176
126
  it "backward compatible" do
177
- fluent_logger = Fluent::Logger::FluentLogger.new('logger-test', 'localhost', fluentd_port)
127
+ fluent_logger = Fluent::Logger::FluentLogger.new('logger-test', 'localhost', fluentd.port)
178
128
  host, port = fluent_logger.instance_eval { [@host, @port] }
179
129
  expect(host).to eq 'localhost'
180
- expect(port).to eq fluentd_port
130
+ expect(port).to eq fluentd.port
181
131
  end
182
132
 
183
133
  it "hash argument" do
184
134
  fluent_logger = Fluent::Logger::FluentLogger.new('logger-test', {
185
135
  :host => 'localhost',
186
- :port => fluentd_port
136
+ :port => fluentd.port
187
137
  })
188
138
 
189
139
  host, port = fluent_logger.instance_eval { [@host, @port] }
190
140
  expect(host).to eq 'localhost'
191
- expect(port).to eq fluentd_port
141
+ expect(port).to eq fluentd.port
192
142
  end
193
143
  end
194
144
  end
@@ -197,8 +147,8 @@ EOF
197
147
  context('fluent logger interface') do
198
148
  it ('post & close') {
199
149
  expect(logger.post('tag', {'a' => 'b'})).to be false
200
- wait_transfer # even if wait
201
- expect(queue.last).to be_nil
150
+ fluentd.wait_transfer # even if wait
151
+ expect(fluentd.queue.last).to be_nil
202
152
  logger.close
203
153
  logger_io.rewind
204
154
  log = logger_io.read
@@ -209,8 +159,8 @@ EOF
209
159
  it ('post limit over') do
210
160
  logger.limit = 100
211
161
  logger.post('tag', {'a' => 'b'})
212
- wait_transfer # even if wait
213
- expect(queue.last).to be_nil
162
+ fluentd.wait_transfer # even if wait
163
+ expect(fluentd.queue.last).to be_nil
214
164
 
215
165
  logger_io.rewind
216
166
  expect(logger_io.read).not_to match /Can't send logs to/
@@ -226,9 +176,9 @@ EOF
226
176
  expect_any_instance_of(Fluent::Logger::FluentLogger).to receive(:log_reconnect_error).once.and_call_original
227
177
 
228
178
  logger.post('tag', {'a' => 'b'})
229
- wait_transfer # even if wait
179
+ fluentd.wait_transfer # even if wait
230
180
  logger.post('tag', {'a' => 'b'})
231
- wait_transfer # even if wait
181
+ fluentd.wait_transfer # even if wait
232
182
  logger_io.rewind
233
183
  expect(logger_io.read).to match /Failed to connect/
234
184
  end
@@ -253,8 +203,8 @@ EOF
253
203
  logger.limit = 100
254
204
  event_1 = {'a' => 'b'}
255
205
  logger.post('tag', event_1)
256
- wait_transfer # even if wait
257
- expect(queue.last).to be(nil)
206
+ fluentd.wait_transfer # even if wait
207
+ expect(fluentd.queue.last).to be(nil)
258
208
 
259
209
  logger_io.rewind
260
210
  expect(logger_io.read).not_to match(/Can't send logs to/)
@@ -0,0 +1,165 @@
1
+
2
+ require 'spec_helper'
3
+ require 'support/dummy_serverengine'
4
+ require 'support/dummy_fluentd'
5
+
6
+ require 'logger'
7
+ require 'stringio'
8
+
9
+ describe Fluent::Logger::FluentLogger do
10
+ let(:fluentd) {
11
+ DummyFluentd.new
12
+ }
13
+
14
+ let(:level_logger) {
15
+ @logger_io = StringIO.new
16
+ logger = ::Logger.new(@logger_io)
17
+ Fluent::Logger::LevelFluentLogger.new('logger-test', {
18
+ :host => 'localhost',
19
+ :port => fluentd.port,
20
+ :logger => logger,
21
+ :buffer_overflow_handler => buffer_overflow_handler
22
+ })
23
+ }
24
+
25
+ let(:buffer_overflow_handler) { nil }
26
+
27
+ let(:logger_io) {
28
+ @logger_io
29
+ }
30
+
31
+ context "running fluentd" do
32
+
33
+ before(:all) do
34
+ @serverengine = DummyServerengine.new
35
+ @serverengine.startup
36
+ end
37
+
38
+ before(:each) do
39
+ fluentd.startup
40
+ end
41
+
42
+ after(:each) do
43
+ fluentd.shutdown
44
+ end
45
+
46
+ after(:all) do
47
+ @serverengine.shutdown
48
+ end
49
+
50
+ context('::Logger compatible methods') do
51
+ it ('initialize default value') {
52
+ level_fluent_logger = Fluent::Logger::LevelFluentLogger.new('logger-test', {
53
+ :host => 'localhost',
54
+ :port => fluentd.port,
55
+ :logger => ::Logger.new(StringIO.new),
56
+ :buffer_overflow_handler => buffer_overflow_handler
57
+ })
58
+ expect(level_fluent_logger.level).to eq 0
59
+ expect(level_fluent_logger.progname).to be_nil
60
+ }
61
+
62
+ it ('close') {
63
+ expect(level_logger).to be_connect
64
+ level_logger.close
65
+ expect(level_logger).not_to be_connect
66
+ }
67
+
68
+ it ('reopen') {
69
+ expect(level_logger).to be_connect
70
+ level_logger.reopen
71
+ expect(level_logger).not_to be_connect
72
+ expect(level_logger.info('logger reopen test')).to be true
73
+ }
74
+ end
75
+
76
+ context('add with level') do
77
+ it ('add progname') {
78
+ expect(level_logger.info('some_application'){ 'some application running' }).to be true
79
+ fluentd.wait_transfer
80
+ expect(fluentd.queue.last).to eq ['logger-test.info', {'level' => 'INFO', 'message' => 'some application running', 'progname' => 'some_application' }]
81
+ }
82
+
83
+ it ('send log debug') {
84
+ expect(level_logger.debug('some_application')).to be true
85
+ fluentd.wait_transfer
86
+ expect(fluentd.queue.last).to eq ['logger-test.debug', {'level' => 'DEBUG', 'message' => 'some_application' }]
87
+ }
88
+
89
+ it ('send log info') {
90
+ expect(level_logger.info('some_application')).to be true
91
+ fluentd.wait_transfer
92
+ expect(fluentd.queue.last).to eq ['logger-test.info', {'level' => 'INFO', 'message' => 'some_application' }]
93
+ }
94
+
95
+ it ('send log warn') {
96
+ expect(level_logger.warn('some_application')).to be true
97
+ fluentd.wait_transfer
98
+ expect(fluentd.queue.last).to eq ['logger-test.warn', {'level' => 'WARN', 'message' => 'some_application' }]
99
+ }
100
+
101
+ it ('send log error') {
102
+ expect(level_logger.error('some_application')).to be true
103
+ fluentd.wait_transfer
104
+ expect(fluentd.queue.last).to eq ['logger-test.error', {'level' => 'ERROR', 'message' => 'some_application' }]
105
+ }
106
+
107
+ it ('send log fatal') {
108
+ expect(level_logger.fatal('some_application')).to be true
109
+ fluentd.wait_transfer
110
+ expect(fluentd.queue.last).to eq ['logger-test.fatal', {'level' => 'FATAL', 'message' => 'some_application' }]
111
+ }
112
+
113
+ it ('not send log debug') {
114
+ level_logger.level = ::Logger::FATAL
115
+
116
+ expect(level_logger.debug('some_application')).to be true
117
+ fluentd.wait_transfer
118
+ expect(fluentd.queue).to eq []
119
+ }
120
+
121
+ it ('not send log info') {
122
+ level_logger.level = ::Logger::FATAL
123
+
124
+ expect(level_logger.info('some_application')).to be true
125
+ fluentd.wait_transfer
126
+ expect(fluentd.queue).to eq []
127
+ }
128
+
129
+ it ('not send log warn') {
130
+ level_logger.level = ::Logger::FATAL
131
+
132
+ expect(level_logger.warn('some_application')).to be true
133
+ fluentd.wait_transfer
134
+ expect(fluentd.queue).to eq []
135
+ }
136
+
137
+ it ('not send log error') {
138
+ level_logger.level = ::Logger::FATAL
139
+
140
+ expect(level_logger.error('some_application')).to be true
141
+ fluentd.wait_transfer
142
+ expect(fluentd.queue).to eq []
143
+ }
144
+
145
+ it ('define formatter') {
146
+ level_logger.level = ::Logger::DEBUG
147
+ level_logger.formatter = proc do |severity, datetime, progname, message|
148
+ map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
149
+ map[:message] = message if message
150
+ map[:progname] = progname if progname
151
+ map[:stage] = "development"
152
+ map[:service_name] = "some service"
153
+ map
154
+ end
155
+
156
+ expect(level_logger.error('some_application')).to be true
157
+ fluentd.wait_transfer
158
+ expect(fluentd.queue.last).to eq [
159
+ 'logger-test.error',
160
+ {'level' => 'ERROR', 'message' => 'some_application', 'stage' => 'development', 'service_name' => 'some service'}
161
+ ]
162
+ }
163
+ end
164
+ end
165
+ end
@@ -14,11 +14,15 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require 'fluent/output'
18
+
17
19
  module Fluent
18
20
  class TestOutput < Output
19
21
  Plugin.register_output('test', self)
20
22
 
21
23
  def initialize
24
+ super
25
+
22
26
  @emit_streams = []
23
27
  @name = nil
24
28
  end
@@ -54,15 +58,19 @@ module Fluent
54
58
  end
55
59
 
56
60
  def configure(conf)
61
+ super
62
+
57
63
  if name = conf['name']
58
64
  @name = name
59
65
  end
60
66
  end
61
67
 
62
68
  def start
69
+ super
63
70
  end
64
71
 
65
72
  def shutdown
73
+ super
66
74
  end
67
75
 
68
76
  def emit(tag, es, chain)
@@ -0,0 +1,82 @@
1
+ require 'fluent/load'
2
+ require 'fluent/test'
3
+ require 'socket'
4
+ require 'plugin/out_test'
5
+ require 'stringio'
6
+
7
+ class DummyFluentd
8
+ def initialize
9
+ output.emits.clear rescue nil
10
+ end
11
+
12
+ WAIT = ENV['WAIT'] ? ENV['WAIT'].to_f : 0.1
13
+
14
+ def wait_transfer
15
+ sleep WAIT
16
+ end
17
+
18
+ def port
19
+ return @port if @port
20
+ @port = 60001
21
+ loop do
22
+ begin
23
+ TCPServer.open('localhost', @port).close
24
+ break
25
+ rescue Errno::EADDRINUSE
26
+ @port += 1
27
+ end
28
+ end
29
+ @port
30
+ end
31
+
32
+ def output
33
+ sleep 0.0001 # next tick
34
+ if Fluent::Engine.respond_to?(:match)
35
+ Fluent::Engine.match('logger-test').output
36
+ else
37
+ Fluent::Engine.root_agent.event_router.match('logger-test')
38
+ end
39
+ end
40
+
41
+ def queue
42
+ queue = []
43
+ output.emits.each {|tag, time, record|
44
+ queue << [tag, record]
45
+ }
46
+ queue
47
+ end
48
+
49
+ def startup
50
+ config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
51
+ <source>
52
+ type forward
53
+ port #{port}
54
+ </source>
55
+ <match logger-test.**>
56
+ type test
57
+ </match>
58
+ EOF
59
+ Fluent::Test.setup
60
+ Fluent::Engine.run_configure(config)
61
+ @coolio_default_loop = nil
62
+ @thread = Thread.new {
63
+ @coolio_default_loop = Coolio::Loop.default
64
+ Fluent::Engine.run
65
+ }
66
+ wait_transfer
67
+ end
68
+
69
+ def shutdown
70
+ @coolio_default_loop.stop rescue nil
71
+ begin
72
+ Fluent::Engine.stop
73
+ rescue => e
74
+ # for v0.12, calling stop may cause "loop not running" by internal default loop
75
+ if e.message == "loop not running"
76
+ Fluent::Engine.send :shutdown
77
+ end
78
+ end
79
+ @thread.join
80
+ @coolio_default_loop = @thread = nil
81
+ end
82
+ end
@@ -0,0 +1,18 @@
1
+ class DummyServerengine
2
+ def initialize
3
+ end
4
+
5
+ def startup
6
+ @server = nil
7
+ if defined?(ServerEngine) # for v0.14. in_forward requires socket manager server
8
+ socket_manager_path = ServerEngine::SocketManager::Server.generate_path
9
+ @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
10
+ ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
11
+ end
12
+ @server
13
+ end
14
+
15
+ def shutdown
16
+ @server.close if @server
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-15 00:00:00.000000000 Z
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -114,6 +114,7 @@ files:
114
114
  - COPYING
115
115
  - ChangeLog
116
116
  - Gemfile
117
+ - Gemfile.v0.12
117
118
  - README.md
118
119
  - Rakefile
119
120
  - VERSION
@@ -124,6 +125,7 @@ files:
124
125
  - lib/fluent/logger/console_logger.rb
125
126
  - lib/fluent/logger/fluent_logger.rb
126
127
  - lib/fluent/logger/fluent_logger/cui.rb
128
+ - lib/fluent/logger/level_fluent_logger.rb
127
129
  - lib/fluent/logger/logger_base.rb
128
130
  - lib/fluent/logger/null_logger.rb
129
131
  - lib/fluent/logger/test_logger.rb
@@ -131,11 +133,14 @@ files:
131
133
  - lib/fluent/logger/version.rb
132
134
  - spec/console_logger_spec.rb
133
135
  - spec/fluent_logger_spec.rb
136
+ - spec/level_fluent_logger_spec.rb
134
137
  - spec/logger_base_spec.rb
135
138
  - spec/logger_spec.rb
136
139
  - spec/null_logger_spec.rb
137
140
  - spec/plugin/out_test.rb
138
141
  - spec/spec_helper.rb
142
+ - spec/support/dummy_fluentd.rb
143
+ - spec/support/dummy_serverengine.rb
139
144
  - spec/support/timecop.rb
140
145
  - spec/test_logger_spec.rb
141
146
  homepage: https://github.com/fluent/fluent-logger-ruby
@@ -164,10 +169,13 @@ summary: fluent logger for ruby
164
169
  test_files:
165
170
  - spec/console_logger_spec.rb
166
171
  - spec/fluent_logger_spec.rb
172
+ - spec/level_fluent_logger_spec.rb
167
173
  - spec/logger_base_spec.rb
168
174
  - spec/logger_spec.rb
169
175
  - spec/null_logger_spec.rb
170
176
  - spec/plugin/out_test.rb
171
177
  - spec/spec_helper.rb
178
+ - spec/support/dummy_fluentd.rb
179
+ - spec/support/dummy_serverengine.rb
172
180
  - spec/support/timecop.rb
173
181
  - spec/test_logger_spec.rb