fluent-logger 0.6.3 → 0.7.0

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: cb70f375d56167d4fa69310f24457f9697947fa9
4
- data.tar.gz: 25ceec5e3dd80f84368cb28bc0f092d7dbd0766f
3
+ metadata.gz: bdb2dae218ea13bfb25a80b51940a17ec0fbd093
4
+ data.tar.gz: 14ab578fbe8291d111e7d6e232ca888ff946cb4c
5
5
  SHA512:
6
- metadata.gz: 571ef4468e47a4917e6525719594baa7f478f1a2d4b676b5d669a04f9b344bf86cc3edee7d4da1b21d9e2cdd357c4bd829ce03616761efa62ab322e2e52ef054
7
- data.tar.gz: 803ed86c13a44b1b823b2d70ed0d2e60eae9c2e388a9d414751b8301ac6603a218254cad5ebc1c49d4febe410b5c6378d5a18797ca6a8f74bfdd0db502b5870b
6
+ metadata.gz: d4041f0c836aa5c91aa34e166d7073decb3f2ab795b0a60f408a09c79fd75a81fde148b20fbd1ceb3328b9e9e2cc18fdd872e42ecebab9e49255705c43e7f700
7
+ data.tar.gz: 51ae53391e0484ff2ca8dc62c1213c4c4016d1bcbd366de7f4e013341ca09ac0e53a816b7bec2f46d5cfbe092eb2ab716b68ab4b7b885f6bb7fc28a3833726ed
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ Release 0.7.0 - 2017/04/12
2
+
3
+ * Add nanosecond_precision parameter for v0.14
4
+ * Update msgpack dependency to v1.0
5
+
1
6
  Release 0.6.3 - 2017/03/29
2
7
 
3
8
  * Add pending_bytesize method
data/README.md CHANGED
@@ -126,7 +126,20 @@ Fluent::Logger::ConsoleLogger.open(io)
126
126
  Fluent::Logger::NullLogger.open
127
127
  ```
128
128
 
129
- ## Buffer overflow
129
+ ## Tips
130
+
131
+ ### Use nanosecond-precision time
132
+
133
+ To send events with nanosecond-precision time (Fluent 0.14 and up), specify `nanosecond_precision` to `FluentLogger` constructor.
134
+
135
+ ```rb
136
+ log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224, :nanosecond_precision => true)
137
+ # Use nanosecond time instead
138
+ log.post("myapp.access", {"agent" => "foo"})
139
+ log.post_with_time("myapp.access", {"agent" => "foo"}, Time.now) # Need Time object for post_with_time
140
+ ```
141
+
142
+ ### Buffer overflow
130
143
 
131
144
  You can inject your own custom proc to handle buffer overflow in the event of connection failure. This will mitigate the loss of data instead of simply throwing data away.
132
145
 
@@ -156,9 +169,9 @@ Fluent::Logger::FluentLogger.new(nil,
156
169
 
157
170
  |name|description|
158
171
  |---|---|
159
- |Web site|http://fluentd.org/|
160
- |Documents|http://docs.fluentd.org/|
161
- |Source repository|https://github.com/fluent/fluent-logger-ruby|
172
+ |Web site|http://fluentd.org/ |
173
+ |Documents|http://docs.fluentd.org/ |
174
+ |Source repository|https://github.com/fluent/fluent-logger-ruby |
162
175
  |Author|Sadayuki Furuhashi|
163
176
  |Copyright|(c) 2011 FURUHASHI Sadayuki|
164
177
  |License|Apache License, Version 2.0|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.7.0
@@ -30,7 +30,7 @@ EOF
30
30
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
31
31
  gem.require_paths = ['lib']
32
32
 
33
- gem.add_dependency "msgpack", ">= 0.5.6", "< 2"
33
+ gem.add_dependency "msgpack", ">= 1.0.0", "< 2"
34
34
  gem.add_development_dependency 'rake', '>= 0.9.2'
35
35
  gem.add_development_dependency 'rspec', '>= 3.0.0'
36
36
  gem.add_development_dependency 'rspec-its', '>= 1.1.0'
@@ -23,6 +23,30 @@ require 'json'
23
23
 
24
24
  module Fluent
25
25
  module Logger
26
+ class EventTime
27
+ TYPE = 0
28
+
29
+ def initialize(raw_time)
30
+ @time = raw_time
31
+ end
32
+
33
+ def to_msgpack(io = nil)
34
+ @time.to_i.to_msgpack(io)
35
+ end
36
+
37
+ def to_msgpack_ext
38
+ [@time.to_i, @time.nsec].pack('NN')
39
+ end
40
+
41
+ def self.from_msgpack_ext(data)
42
+ new(*data.unpack('NN'))
43
+ end
44
+
45
+ def to_json(*args)
46
+ @time.to_i
47
+ end
48
+ end
49
+
26
50
  class FluentLogger < LoggerBase
27
51
  BUFFER_LIMIT = 8*1024*1024
28
52
  RECONNECT_WAIT = 0.5
@@ -55,6 +79,13 @@ module Fluent
55
79
  @host = options[:host]
56
80
  @port = options[:port]
57
81
  @socket_path = options[:socket_path]
82
+ @nanosecond_precision = options[:nanosecond_precision]
83
+
84
+ @factory = MessagePack::Factory.new
85
+ if @nanosecond_precision
86
+ @factory.register_type(EventTime::TYPE, EventTime)
87
+ end
88
+ @packer = @factory.packer
58
89
 
59
90
  @mon = Monitor.new
60
91
  @pending = nil
@@ -98,7 +129,11 @@ module Fluent
98
129
  def post_with_time(tag, map, time)
99
130
  @logger.debug { "event: #{tag} #{map.to_json}" rescue nil } if @logger.debug?
100
131
  tag = "#{@tag_prefix}.#{tag}" if @tag_prefix
101
- write [tag, time.to_i, map]
132
+ if @nanosecond_precision && time.is_a?(Time)
133
+ write [tag, EventTime.new(time), map]
134
+ else
135
+ write [tag, time.to_i, map]
136
+ end
102
137
  end
103
138
 
104
139
  def close
@@ -147,7 +182,11 @@ module Fluent
147
182
 
148
183
  def to_msgpack(msg)
149
184
  begin
150
- msg.to_msgpack
185
+ @mon.synchronize {
186
+ res = @packer.pack(msg).to_s
187
+ @packer.clear
188
+ res
189
+ }
151
190
  rescue NoMethodError
152
191
  JSON.parse(JSON.generate(msg)).to_msgpack
153
192
  end
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Logger
3
3
 
4
- VERSION = '0.6.3'
4
+ VERSION = '0.7.0'
5
5
 
6
6
  end
7
7
  end
@@ -12,15 +12,26 @@ describe Fluent::Logger::FluentLogger do
12
12
  DummyFluentd.new
13
13
  }
14
14
 
15
- let(:logger) {
15
+ let(:internal_logger) {
16
16
  @logger_io = StringIO.new
17
- logger = ::Logger.new(@logger_io)
18
- Fluent::Logger::FluentLogger.new('logger-test', {
17
+ ::Logger.new(@logger_io)
18
+ }
19
+
20
+ let(:logger_config) {
21
+ {
19
22
  :host => 'localhost',
20
23
  :port => fluentd.port,
21
- :logger => logger,
24
+ :logger => internal_logger,
22
25
  :buffer_overflow_handler => buffer_overflow_handler
23
- })
26
+ }
27
+ }
28
+
29
+ let(:logger) {
30
+ Fluent::Logger::FluentLogger.new('logger-test', logger_config)
31
+ }
32
+
33
+ let(:logger_with_nanosec) {
34
+ Fluent::Logger::FluentLogger.new('logger-test', logger_config.merge(:nanosecond_precision => true))
24
35
  }
25
36
 
26
37
  let(:buffer_overflow_handler) { nil }
@@ -65,6 +76,16 @@ describe Fluent::Logger::FluentLogger do
65
76
  expect(logger.pending_bytesize).to eq 0
66
77
  }
67
78
 
79
+ if defined?(Fluent::EventTime)
80
+ it ('success with nanosecond') {
81
+ expect(logger_with_nanosec.pending_bytesize).to eq 0
82
+ expect(logger_with_nanosec.post('tag', {'a' => 'b'})).to be true
83
+ fluentd.wait_transfer
84
+ expect(fluentd.queue.last).to eq ['logger-test.tag', {'a' => 'b'}]
85
+ expect(fluentd.output.emits.first[1]).to be_a_kind_of(Fluent::EventTime)
86
+ }
87
+ end
88
+
68
89
  it ('close after post') {
69
90
  expect(logger).to be_connect
70
91
  logger.close
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.3
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.6
19
+ version: 1.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.5.6
29
+ version: 1.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -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.2
165
+ rubygems_version: 2.6.11
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: fluent logger for ruby