fluent-logger 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/README.md +63 -0
- data/VERSION +1 -1
- data/lib/fluent/logger/fluent_logger.rb +43 -12
- data/lib/fluent/logger/version.rb +1 -1
- data/spec/fluent_logger_spec.rb +13 -0
- metadata +46 -26
- checksums.yaml +0 -7
- data/README.rdoc +0 -55
data/ChangeLog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Release 0.4.7 - 2013/11/21
|
2
|
+
|
3
|
+
* Suppress log error message with :log_reconnect_error_threshold option
|
4
|
+
* Add FluentLogger#last_error method to get last exception in user code
|
5
|
+
|
1
6
|
Release 0.4.6 - 2013/06/17
|
2
7
|
|
3
8
|
* Raise an ArgumentError when passes invalid argument to post method
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Fluent logger
|
2
|
+
A structured event loger
|
3
|
+
|
4
|
+
## Examples
|
5
|
+
|
6
|
+
### Simple
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'fluent-logger'
|
10
|
+
|
11
|
+
log = Fluent::Logger::FluentLogger.new(nil, :host=>'localhost', :port=>24224)
|
12
|
+
unless log.post("myapp.access", {"agent"=>"foo"})
|
13
|
+
p log.last_error # You can get last error object via last_error method
|
14
|
+
end
|
15
|
+
|
16
|
+
# output: myapp.access {"agent":"foo"}
|
17
|
+
```
|
18
|
+
|
19
|
+
### Singleton
|
20
|
+
```ruby
|
21
|
+
require 'fluent-logger'
|
22
|
+
|
23
|
+
Fluent::Logger::FluentLogger.open(nil, :host=>'localhost', :port=>24224)
|
24
|
+
Fluent::Logger.post("myapp.access", {"agent"=>"foo"})
|
25
|
+
|
26
|
+
# output: myapp.access {"agent":"foo"}
|
27
|
+
```
|
28
|
+
|
29
|
+
### Tag prefix
|
30
|
+
```ruby
|
31
|
+
require 'fluent-logger'
|
32
|
+
|
33
|
+
log = Fluent::Logger::FluentLogger.new('myapp', :host=>'localhost', :port=>24224)
|
34
|
+
log.post("access", {"agent"=>"foo"})
|
35
|
+
|
36
|
+
# output: myapp.access {"agent":"foo"}
|
37
|
+
```
|
38
|
+
|
39
|
+
## Loggers
|
40
|
+
|
41
|
+
### Fluent
|
42
|
+
```ruby
|
43
|
+
Fluent::Logger::FluentLogger.open('tag_prefix', :host=>'localhost', :port=24224)
|
44
|
+
```
|
45
|
+
|
46
|
+
### Console
|
47
|
+
```ruby
|
48
|
+
Fluent::Logger::ConsoleLogger.open(io)
|
49
|
+
```
|
50
|
+
|
51
|
+
### Null
|
52
|
+
```ruby
|
53
|
+
Fluent::Logger::NullLogger.open
|
54
|
+
```
|
55
|
+
|
56
|
+
|name|description|
|
57
|
+
|---|---|
|
58
|
+
|Web site|http://fluent.github.com/|
|
59
|
+
|Documents|http://fluent.github.com/doc/|
|
60
|
+
|Source repository|https://github.com/fluent/fluent-logger-ruby|
|
61
|
+
|Author|Sadayuki Furuhashi|
|
62
|
+
|Copyright|(c) 2011 FURUHASHI Sadayuki|
|
63
|
+
|License|Apache License, Version 2.0|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
@@ -81,6 +81,7 @@ class FluentLogger < LoggerBase
|
|
81
81
|
@connect_error_history = []
|
82
82
|
|
83
83
|
@limit = options[:buffer_limit] || BUFFER_LIMIT
|
84
|
+
@log_reconnect_error_threshold = options[:log_reconnect_error_threshold] || RECONNECT_WAIT_MAX_COUNT
|
84
85
|
|
85
86
|
if logger = options[:logger]
|
86
87
|
@logger = logger
|
@@ -93,15 +94,23 @@ class FluentLogger < LoggerBase
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
97
|
+
@last_error = {}
|
98
|
+
|
96
99
|
begin
|
97
100
|
connect!
|
98
|
-
rescue
|
101
|
+
rescue => e
|
102
|
+
set_last_error(e)
|
99
103
|
@logger.error "Failed to connect fluentd: #{$!}"
|
100
104
|
@logger.error "Connection will be retried."
|
101
105
|
end
|
102
106
|
end
|
103
107
|
|
104
|
-
attr_accessor :limit, :logger
|
108
|
+
attr_accessor :limit, :logger, :log_reconnect_error_threshold
|
109
|
+
attr_reader :last_error
|
110
|
+
|
111
|
+
def last_error
|
112
|
+
@last_error[Thread.current.object_id]
|
113
|
+
end
|
105
114
|
|
106
115
|
def post_with_time(tag, map, time)
|
107
116
|
@logger.debug { "event: #{tag} #{map.to_json}" rescue nil }
|
@@ -114,7 +123,8 @@ class FluentLogger < LoggerBase
|
|
114
123
|
if @pending
|
115
124
|
begin
|
116
125
|
send_data(@pending)
|
117
|
-
rescue
|
126
|
+
rescue => e
|
127
|
+
set_last_error(e)
|
118
128
|
@logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
|
119
129
|
end
|
120
130
|
end
|
@@ -142,10 +152,19 @@ class FluentLogger < LoggerBase
|
|
142
152
|
end
|
143
153
|
end
|
144
154
|
|
155
|
+
def suppress_sec
|
156
|
+
if (sz = @connect_error_history.size) < RECONNECT_WAIT_MAX_COUNT
|
157
|
+
RECONNECT_WAIT * (RECONNECT_WAIT_INCR_RATE ** (sz - 1))
|
158
|
+
else
|
159
|
+
RECONNECT_WAIT_MAX
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
145
163
|
def write(msg)
|
146
164
|
begin
|
147
165
|
data = to_msgpack(msg)
|
148
|
-
rescue
|
166
|
+
rescue => e
|
167
|
+
set_last_error(e)
|
149
168
|
@logger.error("FluentLogger: Can't convert to msgpack: #{msg.inspect}: #{$!}")
|
150
169
|
return false
|
151
170
|
end
|
@@ -159,11 +178,6 @@ class FluentLogger < LoggerBase
|
|
159
178
|
|
160
179
|
# suppress reconnection burst
|
161
180
|
if !@connect_error_history.empty? && @pending.bytesize <= @limit
|
162
|
-
if (sz = @connect_error_history.size) < RECONNECT_WAIT_MAX_COUNT
|
163
|
-
suppress_sec = RECONNECT_WAIT * (RECONNECT_WAIT_INCR_RATE ** (sz - 1))
|
164
|
-
else
|
165
|
-
suppress_sec = RECONNECT_WAIT_MAX
|
166
|
-
end
|
167
181
|
if Time.now.to_i - @connect_error_history.last < suppress_sec
|
168
182
|
return false
|
169
183
|
end
|
@@ -173,7 +187,8 @@ class FluentLogger < LoggerBase
|
|
173
187
|
send_data(@pending)
|
174
188
|
@pending = nil
|
175
189
|
true
|
176
|
-
rescue
|
190
|
+
rescue => e
|
191
|
+
set_last_error(e)
|
177
192
|
if @pending.bytesize > @limit
|
178
193
|
@logger.error("FluentLogger: Can't send logs to #{@host}:#{@port}: #{$!}")
|
179
194
|
@pending = nil
|
@@ -210,12 +225,28 @@ class FluentLogger < LoggerBase
|
|
210
225
|
@con = TCPSocket.new(@host, @port)
|
211
226
|
@con.sync = true
|
212
227
|
@connect_error_history.clear
|
213
|
-
|
228
|
+
@logged_reconnect_error = false
|
229
|
+
rescue => e
|
214
230
|
@connect_error_history << Time.now.to_i
|
215
231
|
if @connect_error_history.size > RECONNECT_WAIT_MAX_COUNT
|
216
232
|
@connect_error_history.shift
|
217
233
|
end
|
218
|
-
|
234
|
+
|
235
|
+
if @connect_error_history.size >= @log_reconnect_error_threshold && !@logged_reconnect_error
|
236
|
+
log_reconnect_error
|
237
|
+
@logged_reconnect_error = true
|
238
|
+
end
|
239
|
+
|
240
|
+
raise e
|
241
|
+
end
|
242
|
+
|
243
|
+
def log_reconnect_error
|
244
|
+
@logger.error("FluentLogger: Can't connect to #{@host}:#{@port}(#{@connect_error_history.size} retried): #{$!}")
|
245
|
+
end
|
246
|
+
|
247
|
+
def set_last_error(e)
|
248
|
+
# TODO: Check non GVL env
|
249
|
+
@last_error[Thread.current.object_id] = e
|
219
250
|
end
|
220
251
|
end
|
221
252
|
|
data/spec/fluent_logger_spec.rb
CHANGED
@@ -225,6 +225,19 @@ EOF
|
|
225
225
|
logger_io.rewind
|
226
226
|
logger_io.read.should =~ /Can't send logs to/
|
227
227
|
end
|
228
|
+
|
229
|
+
it ('log connect error once') do
|
230
|
+
logger.stub(:suppress_sec).and_return(-1)
|
231
|
+
logger.log_reconnect_error_threshold = 1
|
232
|
+
logger.should_receive(:log_reconnect_error).once.and_call_original
|
233
|
+
|
234
|
+
logger.post('tag', {'a' => 'b'})
|
235
|
+
wait_transfer # even if wait
|
236
|
+
logger.post('tag', {'a' => 'b'})
|
237
|
+
wait_transfer # even if wait
|
238
|
+
logger_io.rewind
|
239
|
+
logger_io.read.should =~ /Can't connect to/
|
240
|
+
end
|
228
241
|
end
|
229
242
|
end
|
230
243
|
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Sadayuki Furuhashi
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: yajl-ruby
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,20 +30,21 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: msgpack
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: 0.4.4
|
34
|
-
- - '!='
|
38
|
+
- - ! '!='
|
35
39
|
- !ruby/object:Gem::Version
|
36
40
|
version: 0.5.0
|
37
|
-
- - '!='
|
41
|
+
- - ! '!='
|
38
42
|
- !ruby/object:Gem::Version
|
39
43
|
version: 0.5.1
|
40
|
-
- - '!='
|
44
|
+
- - ! '!='
|
41
45
|
- !ruby/object:Gem::Version
|
42
46
|
version: 0.5.2
|
43
|
-
- - '!='
|
47
|
+
- - ! '!='
|
44
48
|
- !ruby/object:Gem::Version
|
45
49
|
version: 0.5.3
|
46
50
|
- - <
|
@@ -49,20 +53,21 @@ dependencies:
|
|
49
53
|
type: :runtime
|
50
54
|
prerelease: false
|
51
55
|
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
52
57
|
requirements:
|
53
|
-
- - '>='
|
58
|
+
- - ! '>='
|
54
59
|
- !ruby/object:Gem::Version
|
55
60
|
version: 0.4.4
|
56
|
-
- - '!='
|
61
|
+
- - ! '!='
|
57
62
|
- !ruby/object:Gem::Version
|
58
63
|
version: 0.5.0
|
59
|
-
- - '!='
|
64
|
+
- - ! '!='
|
60
65
|
- !ruby/object:Gem::Version
|
61
66
|
version: 0.5.1
|
62
|
-
- - '!='
|
67
|
+
- - ! '!='
|
63
68
|
- !ruby/object:Gem::Version
|
64
69
|
version: 0.5.2
|
65
|
-
- - '!='
|
70
|
+
- - ! '!='
|
66
71
|
- !ruby/object:Gem::Version
|
67
72
|
version: 0.5.3
|
68
73
|
- - <
|
@@ -71,57 +76,65 @@ dependencies:
|
|
71
76
|
- !ruby/object:Gem::Dependency
|
72
77
|
name: rake
|
73
78
|
requirement: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
74
80
|
requirements:
|
75
|
-
- - '>='
|
81
|
+
- - ! '>='
|
76
82
|
- !ruby/object:Gem::Version
|
77
83
|
version: 0.9.2
|
78
84
|
type: :development
|
79
85
|
prerelease: false
|
80
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
81
88
|
requirements:
|
82
|
-
- - '>='
|
89
|
+
- - ! '>='
|
83
90
|
- !ruby/object:Gem::Version
|
84
91
|
version: 0.9.2
|
85
92
|
- !ruby/object:Gem::Dependency
|
86
93
|
name: rspec
|
87
94
|
requirement: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
88
96
|
requirements:
|
89
|
-
- - '>='
|
97
|
+
- - ! '>='
|
90
98
|
- !ruby/object:Gem::Version
|
91
99
|
version: 2.7.0
|
92
100
|
type: :development
|
93
101
|
prerelease: false
|
94
102
|
version_requirements: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
95
104
|
requirements:
|
96
|
-
- - '>='
|
105
|
+
- - ! '>='
|
97
106
|
- !ruby/object:Gem::Version
|
98
107
|
version: 2.7.0
|
99
108
|
- !ruby/object:Gem::Dependency
|
100
109
|
name: simplecov
|
101
110
|
requirement: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
102
112
|
requirements:
|
103
|
-
- - '>='
|
113
|
+
- - ! '>='
|
104
114
|
- !ruby/object:Gem::Version
|
105
115
|
version: 0.5.4
|
106
116
|
type: :development
|
107
117
|
prerelease: false
|
108
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
109
120
|
requirements:
|
110
|
-
- - '>='
|
121
|
+
- - ! '>='
|
111
122
|
- !ruby/object:Gem::Version
|
112
123
|
version: 0.5.4
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: timecop
|
115
126
|
requirement: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
116
128
|
requirements:
|
117
|
-
- - '>='
|
129
|
+
- - ! '>='
|
118
130
|
- !ruby/object:Gem::Version
|
119
131
|
version: 0.3.0
|
120
132
|
type: :development
|
121
133
|
prerelease: false
|
122
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
123
136
|
requirements:
|
124
|
-
- - '>='
|
137
|
+
- - ! '>='
|
125
138
|
- !ruby/object:Gem::Version
|
126
139
|
version: 0.3.0
|
127
140
|
description: fluent logger for ruby
|
@@ -139,7 +152,7 @@ files:
|
|
139
152
|
- COPYING
|
140
153
|
- ChangeLog
|
141
154
|
- Gemfile
|
142
|
-
- README.
|
155
|
+
- README.md
|
143
156
|
- Rakefile
|
144
157
|
- VERSION
|
145
158
|
- bin/fluent-post
|
@@ -164,26 +177,33 @@ files:
|
|
164
177
|
- spec/test_logger_spec.rb
|
165
178
|
homepage: https://github.com/fluent/fluent-logger-ruby
|
166
179
|
licenses: []
|
167
|
-
metadata: {}
|
168
180
|
post_install_message:
|
169
181
|
rdoc_options: []
|
170
182
|
require_paths:
|
171
183
|
- lib
|
172
184
|
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
173
186
|
requirements:
|
174
|
-
- - '>='
|
187
|
+
- - ! '>='
|
175
188
|
- !ruby/object:Gem::Version
|
176
189
|
version: '0'
|
190
|
+
segments:
|
191
|
+
- 0
|
192
|
+
hash: 3553729463111660525
|
177
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
178
195
|
requirements:
|
179
|
-
- - '>='
|
196
|
+
- - ! '>='
|
180
197
|
- !ruby/object:Gem::Version
|
181
198
|
version: '0'
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
hash: 3553729463111660525
|
182
202
|
requirements: []
|
183
203
|
rubyforge_project:
|
184
|
-
rubygems_version:
|
204
|
+
rubygems_version: 1.8.23
|
185
205
|
signing_key:
|
186
|
-
specification_version:
|
206
|
+
specification_version: 3
|
187
207
|
summary: fluent logger for ruby
|
188
208
|
test_files:
|
189
209
|
- spec/console_logger_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 646a1e0a022169db9fa2392e5e4e4077b98fe82d
|
4
|
-
data.tar.gz: bc397f0a66e90d51e6c5d10912f2c735f8feab6c
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 4ab7cc6f13741664506d4ecb537effb9630efaf8cfc81f496dfc2d9d65ee944d9f835b21e95c45d8133c51e98e7992ffb5d5a512ce14e6a630f6aff714be94d7
|
7
|
-
data.tar.gz: 762bd7f474ea59cd7e689eb20d99d3926f7acd821bd9121c49afddb0ce2da1e47cbdf6ed144c3f296ce56a952c5358c32123702d99938508ea6b77541bfdb146
|
data/README.rdoc
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
= Fluent logger
|
2
|
-
|
3
|
-
A structured event loger
|
4
|
-
|
5
|
-
== Examples
|
6
|
-
|
7
|
-
=== Simple
|
8
|
-
|
9
|
-
require 'fluent-logger'
|
10
|
-
|
11
|
-
log = Fluent::Logger::FluentLogger.new(nil, :host=>'localhost', :port=>24224)
|
12
|
-
log.post("myapp.access", {"agent"=>"foo"})
|
13
|
-
|
14
|
-
# output: myapp.access {"agent":"foo"}
|
15
|
-
|
16
|
-
=== Singleton
|
17
|
-
|
18
|
-
require 'fluent-logger'
|
19
|
-
|
20
|
-
Fluent::Logger::FluentLogger.open(nil, :host=>'localhost', :port=>24224)
|
21
|
-
Fluent::Logger.post("myapp.access", {"agent"=>"foo"})
|
22
|
-
|
23
|
-
# output: myapp.access {"agent":"foo"}
|
24
|
-
|
25
|
-
=== Tag prefix
|
26
|
-
|
27
|
-
require 'fluent-logger'
|
28
|
-
|
29
|
-
log = Fluent::Logger::FluentLogger.new('myapp', :host=>'localhost', :port=>24224)
|
30
|
-
log.post("access", {"agent"=>"foo"})
|
31
|
-
|
32
|
-
# output: myapp.access {"agent":"foo"}
|
33
|
-
|
34
|
-
== Loggers
|
35
|
-
|
36
|
-
=== Fluent
|
37
|
-
|
38
|
-
Fluent::Logger::FluentLogger.open('tag_prefix', :host=>'localhost', :port=24224)
|
39
|
-
|
40
|
-
=== Console
|
41
|
-
|
42
|
-
Fluent::Logger::ConsoleLogger.open(io)
|
43
|
-
|
44
|
-
=== Null
|
45
|
-
|
46
|
-
Fluent::Logger::NullLogger.open
|
47
|
-
|
48
|
-
|
49
|
-
Web site:: http://fluent.github.com/
|
50
|
-
Documents:: http://fluent.github.com/doc/
|
51
|
-
Source repository:: https://github.com/fluent/fluent-logger-ruby
|
52
|
-
Author:: Sadayuki Furuhashi
|
53
|
-
Copyright:: (c) 2011 FURUHASHI Sadayuki
|
54
|
-
License:: Apache License, Version 2.0
|
55
|
-
|