fluent-logger 0.6.1 → 0.6.2

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: b697bc01bf042c2ecafc345c71dd0c133d08519f
4
- data.tar.gz: 490cf5426952cca33f6a6a98cd4d150ef2ddad43
3
+ metadata.gz: cfed8c8167db552fe22b3b030b62041a5b523636
4
+ data.tar.gz: fdca6f7fcb62bb64364ae76af2a05bb287756ba2
5
5
  SHA512:
6
- metadata.gz: d72fb3e957716c2003be82e669da0d14902631f98c710e32b530a5c099bbd56ec1e91e4cc392da55c00c0aaf11de08431682458e5ef32fbcaa6c78bda2efa371
7
- data.tar.gz: 16783931f838a10cf82346f918faff6d8bab0f47172eaaf1bbc991a01549f2e704a3c45fa32f379b6133a481ca6b9b3a2b54793e473cbec321773df05d41944c
6
+ metadata.gz: dae9cd5b7df431025125450fa88e53700d6a6b2b16d78ff327fb3e5f5ea4599023cec6afeae588251ba2e88a5e7d31cb6746466f9882fa855d68d0960be2026a
7
+ data.tar.gz: 0e3b5eb2f7a88a20295779c63a556201eb3d2c1098488f92a6dcc9ee93b5630f0d9770803ffc5c99d7370105ed244b50e49e0ed8c21001b493b9a331d858fb4e
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ rvm:
4
4
  - 2.1
5
5
  - 2.2
6
6
  - 2.3.1
7
+ - 2.4.0
7
8
  - ruby-head
8
9
 
9
10
  gemfile:
@@ -27,5 +28,7 @@ matrix:
27
28
  gemfile: Gemfile.v0.12
28
29
  - rvm: 2.3.1
29
30
  gemfile: Gemfile.v0.12
31
+ - rvm: 2.4.0
32
+ gemfile: Gemfile.v0.12
30
33
  - rvm: ruby-head
31
34
  gemfile: Gemfile.v0.12
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Release 0.6.2 - 2017/01/17
2
+
3
+ * Add unix domain socket support for `in_unix`
4
+ * LevelFluentLogger uses standard compatible severity formatting
5
+
1
6
  Release 0.6.1 - 2016/11/02
2
7
 
3
8
  * Add LevelFluentLogger: Standard Logger compatible interface
data/README.md CHANGED
@@ -11,8 +11,21 @@ A structured event logger
11
11
  ```ruby
12
12
  require 'fluent-logger'
13
13
 
14
- log = Fluent::Logger::FluentLogger.new(nil, :host=>'localhost', :port=>24224)
15
- unless log.post("myapp.access", {"agent"=>"foo"})
14
+ log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224)
15
+ unless log.post("myapp.access", {"agent" => "foo"})
16
+ p log.last_error # You can get last error object via last_error method
17
+ end
18
+
19
+ # output: myapp.access {"agent":"foo"}
20
+ ```
21
+
22
+ ### UNIX socket
23
+
24
+ ```ruby
25
+ require 'fluent-logger'
26
+
27
+ log = Fluent::Logger::FluentLogger.new(nil, :socket_path => "/tmp/fluent.sock")
28
+ unless log.post("myapp.access", {"agent" => "foo"})
16
29
  p log.last_error # You can get last error object via last_error method
17
30
  end
18
31
 
@@ -23,8 +36,8 @@ end
23
36
  ```ruby
24
37
  require 'fluent-logger'
25
38
 
26
- Fluent::Logger::FluentLogger.open(nil, :host=>'localhost', :port=>24224)
27
- Fluent::Logger.post("myapp.access", {"agent"=>"foo"})
39
+ Fluent::Logger::FluentLogger.open(nil, :host => 'localhost', :port => 24224)
40
+ Fluent::Logger.post("myapp.access", {"agent" => "foo"})
28
41
 
29
42
  # output: myapp.access {"agent":"foo"}
30
43
  ```
@@ -33,8 +46,8 @@ Fluent::Logger.post("myapp.access", {"agent"=>"foo"})
33
46
  ```ruby
34
47
  require 'fluent-logger'
35
48
 
36
- log = Fluent::Logger::FluentLogger.new('myapp', :host=>'localhost', :port=>24224)
37
- log.post("access", {"agent"=>"foo"})
49
+ log = Fluent::Logger::FluentLogger.new('myapp', :host => 'localhost', :port => 24224)
50
+ log.post("access", {"agent" => "foo"})
38
51
 
39
52
  # output: myapp.access {"agent":"foo"}
40
53
  ```
@@ -59,7 +72,7 @@ f.warn("some application running.")
59
72
  ```ruby
60
73
  require 'fluent-logger'
61
74
  f = Fluent::Logger::LevelFluentLogger.new('fluent')
62
- f.info("some_application"){"some application running."}
75
+ f.info("some_application") {"some application running."}
63
76
  # output: fluent.info: {"level":"INFO","message":"some application running.","progname":"some_application"}
64
77
  ```
65
78
 
@@ -69,7 +82,7 @@ f.info("some_application"){"some application running."}
69
82
  require 'fluent-logger'
70
83
  f = Fluent::Logger::LevelFluentLogger.new('fluent')
71
84
  f.level = Logger::WARN
72
- f.info("some_application"){"some application running."}
85
+ f.info("some_application") {"some application running."}
73
86
  ```
74
87
 
75
88
  Log level is ERROR so no output.
@@ -84,7 +97,7 @@ require 'fluent-logger'
84
97
  f = Fluent::Logger::LevelFluentLogger.new('fluent')
85
98
 
86
99
  f.formatter = proc do |severity, datetime, progname, message|
87
- map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
100
+ map = { level: severity }
88
101
  map[:message] = message if message
89
102
  map[:progname] = progname if progname
90
103
  map[:stage] = ENV['RAILS_ENV']
@@ -100,7 +113,7 @@ f.info("some_application"){"some application running."}
100
113
 
101
114
  ### Fluent
102
115
  ```ruby
103
- Fluent::Logger::FluentLogger.open('tag_prefix', :host=>'localhost', :port=>24224)
116
+ Fluent::Logger::FluentLogger.open('tag_prefix', :host => 'localhost', :port => 24224)
104
117
  ```
105
118
 
106
119
  ### Console
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2
@@ -29,7 +29,7 @@ module Fluent
29
29
  RECONNECT_WAIT_INCR_RATE = 1.5
30
30
  RECONNECT_WAIT_MAX = 60
31
31
  RECONNECT_WAIT_MAX_COUNT =
32
- (1..100).inject(RECONNECT_WAIT_MAX / RECONNECT_WAIT) {|r,i|
32
+ (1..100).inject(RECONNECT_WAIT_MAX / RECONNECT_WAIT) { |r, i|
33
33
  break i + 1 if r < RECONNECT_WAIT_INCR_RATE
34
34
  r / RECONNECT_WAIT_INCR_RATE
35
35
  }
@@ -54,16 +54,16 @@ module Fluent
54
54
  @tag_prefix = tag_prefix
55
55
  @host = options[:host]
56
56
  @port = options[:port]
57
+ @socket_path = options[:socket_path]
57
58
 
58
59
  @mon = Monitor.new
59
60
  @pending = nil
60
61
  @connect_error_history = []
61
62
 
62
63
  @limit = options[:buffer_limit] || BUFFER_LIMIT
63
- @log_reconnect_error_threshold = options[:log_reconnect_error_threshold] || RECONNECT_WAIT_MAX_COUNT
64
+ @log_reconnect_error_threshold = options[:log_reconnect_error_threshold] || RECONNECT_WAIT_MAX_COUNT
64
65
 
65
66
  @buffer_overflow_handler = options[:buffer_overflow_handler]
66
-
67
67
  if logger = options[:logger]
68
68
  @logger = logger
69
69
  else
@@ -108,7 +108,7 @@ module Fluent
108
108
  send_data(@pending)
109
109
  rescue => e
110
110
  set_last_error(e)
111
- @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
111
+ @logger.error("FluentLogger: Can't send logs to #{connection_string}: #{$!}")
112
112
  call_buffer_overflow_handler(@pending)
113
113
  end
114
114
  end
@@ -123,7 +123,20 @@ module Fluent
123
123
  @con && !@con.closed?
124
124
  end
125
125
 
126
+ def create_socket!
127
+ if @socket_path
128
+ @con = UNIXSocket.new(@socket_path)
129
+ else
130
+ @con = TCPSocket.new(@host, @port)
131
+ end
132
+ end
133
+
134
+ def connection_string
135
+ @socket_path ? "#{@socket_path}" : "#{@host}:#{@port}"
136
+ end
137
+
126
138
  private
139
+
127
140
  def to_msgpack(msg)
128
141
  begin
129
142
  msg.to_msgpack
@@ -170,7 +183,7 @@ module Fluent
170
183
  rescue => e
171
184
  set_last_error(e)
172
185
  if @pending.bytesize > @limit
173
- @logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
186
+ @logger.error("FluentLogger: Can't send logs to #{connection_string}: #{$!}")
174
187
  call_buffer_overflow_handler(@pending)
175
188
  @pending = nil
176
189
  end
@@ -203,7 +216,7 @@ module Fluent
203
216
  end
204
217
 
205
218
  def connect!
206
- @con = TCPSocket.new(@host, @port)
219
+ create_socket!
207
220
  @con.sync = true
208
221
  @connect_error_history.clear
209
222
  @logged_reconnect_error = false
@@ -230,7 +243,7 @@ module Fluent
230
243
  end
231
244
 
232
245
  def log_reconnect_error
233
- @logger.error("FluentLogger: Can't connect to #{@host}:#{@port}(#{@connect_error_history.size} retried): #{$!}")
246
+ @logger.error("FluentLogger: Can't connect to #{connection_string}(#{@connect_error_history.size} retried): #{$!}")
234
247
  end
235
248
 
236
249
  def set_last_error(e)
@@ -28,7 +28,7 @@ module Fluent
28
28
  def initialize(tag_prefix = nil, *args)
29
29
  @level = ::Logger::DEBUG
30
30
  @default_formatter = proc do |severity, datetime, progname, message|
31
- map = { level: format_severity(severity) }
31
+ map = { level: severity }
32
32
  map[:message] = message if message
33
33
  map[:progname] = progname if progname
34
34
  map
@@ -50,7 +50,7 @@ module Fluent
50
50
  progname = @progname
51
51
  end
52
52
  end
53
- map = format_message(severity, Time.now, progname, message)
53
+ map = format_message(format_severity(severity), Time.now, progname, message)
54
54
  @fluent_logger.post(format_severity(severity).downcase, map)
55
55
  true
56
56
  end
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Logger
3
3
 
4
- VERSION = '0.6.1'
4
+ VERSION = '0.6.2'
5
5
 
6
6
  end
7
7
  end
@@ -119,6 +119,8 @@ describe Fluent::Logger::FluentLogger do
119
119
  expect {
120
120
  logger.post('tag', data)
121
121
  }.to raise_error(ArgumentError)
122
+
123
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
122
124
  }
123
125
  end
124
126
 
@@ -128,6 +130,7 @@ describe Fluent::Logger::FluentLogger do
128
130
  host, port = fluent_logger.instance_eval { [@host, @port] }
129
131
  expect(host).to eq 'localhost'
130
132
  expect(port).to eq fluentd.port
133
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
131
134
  end
132
135
 
133
136
  it "hash argument" do
@@ -139,6 +142,7 @@ describe Fluent::Logger::FluentLogger do
139
142
  host, port = fluent_logger.instance_eval { [@host, @port] }
140
143
  expect(host).to eq 'localhost'
141
144
  expect(port).to eq fluentd.port
145
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
142
146
  end
143
147
  end
144
148
  end
@@ -226,4 +230,44 @@ describe Fluent::Logger::FluentLogger do
226
230
  end
227
231
  end
228
232
  end
233
+
234
+ context "using socket_path" do
235
+
236
+ let(:socket_logger) {
237
+ @logger_io = StringIO.new
238
+ logger = ::Logger.new(@logger_io)
239
+ Fluent::Logger::FluentLogger.new('logger-test', {
240
+ :socket_path => fluentd.socket_path,
241
+ :logger => logger,
242
+ :buffer_overflow_handler => buffer_overflow_handler
243
+ })
244
+ }
245
+
246
+ context "running fluentd" do
247
+ before(:all) do
248
+ @serverengine = DummyServerengine.new
249
+ @serverengine.startup
250
+ end
251
+
252
+ before(:each) do
253
+ fluentd.socket_startup
254
+ end
255
+
256
+ after(:each) do
257
+ fluentd.shutdown
258
+ end
259
+
260
+ after(:all) do
261
+ @serverengine.shutdown
262
+ end
263
+
264
+ context('post') do
265
+ it ('success') {
266
+ expect(socket_logger.post('tag', {'b' => 'a'})).to be true
267
+ fluentd.wait_transfer
268
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'b' => 'a'}]
269
+ }
270
+ end
271
+ end
272
+ end
229
273
  end
@@ -57,12 +57,14 @@ describe Fluent::Logger::FluentLogger do
57
57
  })
58
58
  expect(level_fluent_logger.level).to eq 0
59
59
  expect(level_fluent_logger.progname).to be_nil
60
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
60
61
  }
61
62
 
62
63
  it ('close') {
63
64
  expect(level_logger).to be_connect
64
65
  level_logger.close
65
66
  expect(level_logger).not_to be_connect
67
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
66
68
  }
67
69
 
68
70
  it ('reopen') {
@@ -70,6 +72,7 @@ describe Fluent::Logger::FluentLogger do
70
72
  level_logger.reopen
71
73
  expect(level_logger).not_to be_connect
72
74
  expect(level_logger.info('logger reopen test')).to be true
75
+ fluentd.wait_transfer # ensure the fluentd accepted the connection
73
76
  }
74
77
  end
75
78
 
@@ -145,7 +148,7 @@ describe Fluent::Logger::FluentLogger do
145
148
  it ('define formatter') {
146
149
  level_logger.level = ::Logger::DEBUG
147
150
  level_logger.formatter = proc do |severity, datetime, progname, message|
148
- map = { level: severity.class == Fixnum ? %w(DEBUG INFO WARN ERROR FATAL ANY)[severity] : severity }
151
+ map = { level: severity }
149
152
  map[:message] = message if message
150
153
  map[:progname] = progname if progname
151
154
  map[:stage] = "development"
@@ -9,7 +9,8 @@ class DummyFluentd
9
9
  output.emits.clear rescue nil
10
10
  end
11
11
 
12
- WAIT = ENV['WAIT'] ? ENV['WAIT'].to_f : 0.1
12
+ WAIT = ENV['WAIT'] ? ENV['WAIT'].to_f : 0.3
13
+ SOCKET_PATH = ENV['SOCKET_PATH'] || "/tmp/dummy_fluent.sock"
13
14
 
14
15
  def wait_transfer
15
16
  sleep WAIT
@@ -29,6 +30,10 @@ class DummyFluentd
29
30
  @port
30
31
  end
31
32
 
33
+ def socket_path
34
+ SOCKET_PATH
35
+ end
36
+
32
37
  def output
33
38
  sleep 0.0001 # next tick
34
39
  if Fluent::Engine.respond_to?(:match)
@@ -40,7 +45,7 @@ class DummyFluentd
40
45
 
41
46
  def queue
42
47
  queue = []
43
- output.emits.each {|tag, time, record|
48
+ output.emits.each { |tag, time, record|
44
49
  queue << [tag, record]
45
50
  }
46
51
  queue
@@ -66,6 +71,26 @@ EOF
66
71
  wait_transfer
67
72
  end
68
73
 
74
+ def socket_startup
75
+ config = Fluent::Config.parse(<<EOF, '(logger-spec)', '(logger-spec-dir)', true)
76
+ <source>
77
+ type unix
78
+ path #{socket_path}
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
92
+ end
93
+
69
94
  def shutdown
70
95
  @coolio_default_loop.stop rescue nil
71
96
  begin
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.1
4
+ version: 0.6.2
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-11-02 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  version: '0'
163
163
  requirements: []
164
164
  rubyforge_project:
165
- rubygems_version: 2.5.1
165
+ rubygems_version: 2.5.2
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: fluent logger for ruby