fluent-logger 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,6 @@ rvm:
4
4
  - ree
5
5
  - jruby
6
6
 
7
- before_script:
8
- - git submodule update -i
7
+ before_install: git submodule update -i
9
8
 
10
9
  script: bundle exec rake spec
data/ChangeLog CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ Release 0.4.2 - 2012/03/02
3
+
4
+ * Added TestLogger#tag_queue(tag_name)
5
+ * Added bin/fluent-post cli command
6
+ * Impl default LoggerBase#close
7
+ * Don't change logger.level if :debug=> option is sepcified
8
+
2
9
  Release 0.4.1 - 2011/11/07
3
10
 
4
11
  * added Logger#post_with_time(tag, map, time)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fluent/logger/fluent_logger/cui'
4
+
5
+ res = Fluent::Logger::FluentLogger::CUI.post(ARGV)
6
+ if res[:success]
7
+ warn "post successed. #=> #{res[:data].inspect}"
8
+ else
9
+ warn "post failed. #=> #{res[:data].inspect}"
10
+ exit 1
11
+ end
@@ -24,6 +24,7 @@ module Logger
24
24
  autoload :TestLogger , 'fluent/logger/test_logger'
25
25
  autoload :TextLogger , 'fluent/logger/text_logger'
26
26
  autoload :NullLogger , 'fluent/logger/null_logger'
27
+ autoload :VERSION , 'fluent/logger/version'
27
28
 
28
29
  @@default_logger = nil
29
30
 
@@ -32,7 +32,7 @@ class ConsoleLogger < TextLogger
32
32
  @io = out
33
33
  @on_reopen = Proc.new { }
34
34
  else
35
- raise "Invlaid output: #{out.inspect}"
35
+ raise "Invalid output: #{out.inspect}"
36
36
  end
37
37
  end
38
38
 
@@ -82,11 +82,15 @@ class FluentLogger < LoggerBase
82
82
 
83
83
  @limit = options[:buffer_limit] || BUFFER_LIMIT
84
84
 
85
- @logger = options[:logger] || ::Logger.new(STDERR)
86
- if options[:debug]
87
- @logger.level = ::Logger::DEBUG
85
+ if logger = options[:logger]
86
+ @logger = logger
88
87
  else
89
- @logger.level = ::Logger::INFO
88
+ @logger = ::Logger.new(STDERR)
89
+ if options[:debug]
90
+ @logger.level = ::Logger::DEBUG
91
+ else
92
+ @logger.level = ::Logger::INFO
93
+ end
90
94
  end
91
95
 
92
96
  begin
@@ -0,0 +1,46 @@
1
+
2
+ require 'fluent/logger'
3
+ require 'optparse'
4
+
5
+ module Fluent
6
+ module Logger
7
+ class FluentLogger
8
+
9
+ module CUI
10
+ def post(args)
11
+ options = {
12
+ :port => '24224',
13
+ :host => 'localhost'
14
+ }
15
+
16
+ o = OptionParser.new
17
+ o.version = Fluent::Logger::VERSION
18
+ o.on('-t [tag (default nil)]') {|v| options[:tag] = v }
19
+ o.on('-p [port (default 24224)]') {|v| options[:port] = v }
20
+ o.on('-h [host (default localhost)]') {|v| options[:host] = v }
21
+ o.on('-v [key=value]') {|v|
22
+ key, value = v.split('=')
23
+ (options[:data] ||= {})[key] = value
24
+ }
25
+ o.banner = 'Usage: fluent-post -t tag.foo.bar -v key1=value1 -v key2=value2'
26
+ args = args.to_a
27
+ args << '--help' if args.empty?
28
+ o.parse(args)
29
+
30
+ f = Fluent::Logger::FluentLogger.new(nil, {
31
+ :host => options[:host],
32
+ :port => options[:port]
33
+ })
34
+
35
+ {
36
+ :success => f.post(options[:tag], options[:data]),
37
+ :data => options[:data]
38
+ }
39
+ end
40
+
41
+ extend self
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -30,8 +30,8 @@ class LoggerBase
30
30
  #def post_with_time(tag, map)
31
31
  #end
32
32
 
33
- #def close(map)
34
- #end
33
+ def close
34
+ end
35
35
  end
36
36
 
37
37
  end
@@ -39,6 +39,10 @@ class TestLogger < LoggerBase
39
39
  true
40
40
  end
41
41
 
42
+ def tag_queue(tag)
43
+ @queue.find_all {|map| map.tag == tag }
44
+ end
45
+
42
46
  def close
43
47
  end
44
48
  end
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Logger
3
3
 
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.2'
5
5
 
6
6
  end
7
7
  end
@@ -13,10 +13,13 @@ require 'tempfile'
13
13
  require 'logger'
14
14
  require 'socket'
15
15
  require 'stringio'
16
+ require 'fluent/logger/fluent_logger/cui'
16
17
 
17
18
  $log = Fluent::Log.new(StringIO.new) # XXX should remove $log from fluentd
18
19
 
19
20
  describe Fluent::Logger::FluentLogger do
21
+ WAIT = ENV['WAIT'] ? ENV['WAIT'].to_f : 0.1
22
+
20
23
  let(:fluentd_port) {
21
24
  port = 60001
22
25
  loop do
@@ -59,10 +62,13 @@ describe Fluent::Logger::FluentLogger do
59
62
  queue
60
63
  }
61
64
 
62
- after(:each) do
63
- output.emits.clear rescue nil
64
- end
65
+ after(:each) do
66
+ output.emits.clear rescue nil
67
+ end
65
68
 
69
+ def wait_transfer
70
+ sleep WAIT
71
+ end
66
72
 
67
73
  context "running fluentd" do
68
74
  before(:each) do
@@ -83,21 +89,31 @@ EOF
83
89
  Fluent::Test.setup
84
90
  Fluent::Engine.read_config(tmp.path)
85
91
  @coolio_default_loop = nil
86
- Thread.new {
92
+ @thread = Thread.new {
87
93
  @coolio_default_loop = Coolio::Loop.default
88
94
  Fluent::Engine.run
89
95
  }
90
- sleep 0.001 # next tick
96
+ wait_transfer
91
97
  end
92
98
 
93
99
  after(:each) do
94
100
  @coolio_default_loop.stop
95
101
  Fluent::Engine.send :shutdown
102
+ @thread.join
103
+ end
104
+
105
+ context('Post by CUI') do
106
+ it('post') {
107
+ args = %W(-h localhost -p #{fluentd_port} -t logger-test.tag -v a=b -v foo=bar)
108
+ Fluent::Logger::FluentLogger::CUI.post(args)
109
+ queue.last.should == ['logger-test.tag', {'a' => 'b', 'foo' => 'bar'}]
110
+ }
96
111
  end
97
112
 
98
113
  context('post') do
99
114
  it ('success') {
100
115
  logger.post('tag', {'a' => 'b'}).should be_true
116
+ wait_transfer
101
117
  queue.last.should == ['logger-test.tag', {'a' => 'b'}]
102
118
  }
103
119
 
@@ -108,13 +124,14 @@ EOF
108
124
 
109
125
  logger.post('tag', {'b' => 'c'})
110
126
  logger.should be_connect
127
+ wait_transfer
111
128
  queue.last.should == ['logger-test.tag', {'b' => 'c'}]
112
129
  }
113
130
 
114
131
  it ('large data') {
115
132
  data = {'a' => ('b' * 1000000)}
116
133
  logger.post('tag', data)
117
- sleep 0.01 # wait write
134
+ wait_transfer
118
135
  queue.last.should == ['logger-test.tag', data]
119
136
  }
120
137
 
@@ -125,6 +142,7 @@ EOF
125
142
  'proc' => proc { 1 },
126
143
  }
127
144
  logger.post('tag', data)
145
+ wait_transfer
128
146
  logger_data = queue.last.last
129
147
  logger_data['time'].should == '2008-09-01 10:05:00 UTC'
130
148
  logger_data['proc'].should be
@@ -139,6 +157,7 @@ EOF
139
157
  'NaN' => (0.0/0.0) # JSON don't convert
140
158
  }
141
159
  logger.post('tag', data)
160
+ wait_transfer
142
161
  queue.last.should be_nil
143
162
  logger_io.rewind
144
163
  logger_io.read =~ /FluentLogger: Can't convert to msgpack:/
@@ -171,8 +190,9 @@ EOF
171
190
 
172
191
  context "not running fluentd" do
173
192
  context('fluent logger interface') do
174
- it ('post & close') {
193
+ it ('post & close') {
175
194
  logger.post('tag', {'a' => 'b'}).should be_false
195
+ wait_transfer # even if wait
176
196
  queue.last.should be_nil
177
197
  logger.close
178
198
  logger_io.rewind
@@ -184,6 +204,7 @@ EOF
184
204
  it ('post limit over') do
185
205
  logger.limit = 100
186
206
  logger.post('tag', {'a' => 'b'})
207
+ wait_transfer # even if wait
187
208
  queue.last.should be_nil
188
209
 
189
210
  logger_io.rewind
@@ -12,9 +12,8 @@ describe Fluent::Logger do
12
12
  end
13
13
 
14
14
  it('post') {
15
- time = Time.now
16
- test_logger.should_receive(:post).with('tag1', {:foo => :bar}, time)
17
- Fluent::Logger.post('tag1', {:foo => :bar}, time)
15
+ test_logger.should_receive(:post).with('tag1', {:foo => :bar})
16
+ Fluent::Logger.post('tag1', {:foo => :bar})
18
17
  }
19
18
 
20
19
  it('close') {
@@ -16,6 +16,12 @@ describe Fluent::Logger::TestLogger do
16
16
  its(:last) { should == {:foo => :baz } }
17
17
  its("first.tag") { should == "tag1" }
18
18
  its("last.tag") { should == "tag2" }
19
+
20
+ it("tag_queue") {
21
+ logger.tag_queue('tag1').size.should == 1
22
+ logger.tag_queue('tag2').size.should == 1
23
+ logger.tag_queue('tag3').size.should == 0
24
+ }
19
25
  end
20
26
 
21
27
  context "max" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-07 00:00:00.000000000Z
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
16
- requirement: &70207037595840 !ruby/object:Gem::Requirement
16
+ requirement: &2172185840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70207037595840
24
+ version_requirements: *2172185840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: msgpack
27
- requirement: &70207037595300 !ruby/object:Gem::Requirement
27
+ requirement: &2172185340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.4.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70207037595300
35
+ version_requirements: *2172185340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70207037594800 !ruby/object:Gem::Requirement
38
+ requirement: &2172184880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70207037594800
46
+ version_requirements: *2172184880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70207037594340 !ruby/object:Gem::Requirement
49
+ requirement: &2172184420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70207037594340
57
+ version_requirements: *2172184420
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &70207037593860 !ruby/object:Gem::Requirement
60
+ requirement: &2172183960 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.5.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70207037593860
68
+ version_requirements: *2172183960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
- requirement: &70207037593340 !ruby/object:Gem::Requirement
71
+ requirement: &2172183500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,11 @@ dependencies:
76
76
  version: 0.3.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70207037593340
79
+ version_requirements: *2172183500
80
80
  description: fluent logger for ruby
81
81
  email: frsyuki@gmail.com
82
- executables: []
82
+ executables:
83
+ - fluent-post
83
84
  extensions: []
84
85
  extra_rdoc_files: []
85
86
  files:
@@ -94,11 +95,13 @@ files:
94
95
  - README.rdoc
95
96
  - Rakefile
96
97
  - VERSION
98
+ - bin/fluent-post
97
99
  - fluent-logger.gemspec
98
100
  - lib/fluent-logger.rb
99
101
  - lib/fluent/logger.rb
100
102
  - lib/fluent/logger/console_logger.rb
101
103
  - lib/fluent/logger/fluent_logger.rb
104
+ - lib/fluent/logger/fluent_logger/cui.rb
102
105
  - lib/fluent/logger/logger_base.rb
103
106
  - lib/fluent/logger/null_logger.rb
104
107
  - lib/fluent/logger/test_logger.rb
@@ -124,21 +127,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
127
  - - ! '>='
125
128
  - !ruby/object:Gem::Version
126
129
  version: '0'
127
- segments:
128
- - 0
129
- hash: 3162457063244932466
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
133
133
  - - ! '>='
134
134
  - !ruby/object:Gem::Version
135
135
  version: '0'
136
- segments:
137
- - 0
138
- hash: 3162457063244932466
139
136
  requirements: []
140
137
  rubyforge_project:
141
- rubygems_version: 1.8.10
138
+ rubygems_version: 1.8.17
142
139
  signing_key:
143
140
  specification_version: 3
144
141
  summary: fluent logger for ruby