td-logger 0.3.24 → 0.3.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ require "spec_helper"
2
+
3
+ describe TreasureData::Logger do
4
+ describe ".logger" do
5
+ subject { described_class.logger }
6
+
7
+ context ".open called" do
8
+ before { described_class.open("tag", apikey: "dummy") }
9
+ it { is_expected.to be_kind_of(TreasureData::Logger::TreasureDataLogger) }
10
+ end
11
+
12
+ context ".open_agent called" do
13
+ before { described_class.open_agent("tag") }
14
+ it { is_expected.to be_kind_of(Fluent::Logger::FluentLogger) }
15
+ end
16
+
17
+ context ".open_null called" do
18
+ before { described_class.open_null }
19
+ it { is_expected.to be_kind_of(Fluent::Logger::NullLogger) }
20
+ end
21
+
22
+ context ".open_test called" do
23
+ before { described_class.open_test }
24
+ it { is_expected.to be_kind_of(Fluent::Logger::TestLogger) }
25
+ end
26
+ end
27
+
28
+ describe ".post" do
29
+ let(:args) { ["tag", foo: "dummy"] }
30
+
31
+ it "invoke TreasureData::Logger.post with args" do
32
+ expect(TreasureData::Logger.logger).to receive(:post).with(*args)
33
+ described_class.post(*args)
34
+ end
35
+ end
36
+
37
+ describe ".post_with_time" do
38
+ let(:args) { ["tag", {foo: "dummy"}, Time.now] }
39
+
40
+ it "invoke TreasureData::Logger.post_with_time with args" do
41
+ expect(TreasureData::Logger.logger).to receive(:post_with_time).with(*args)
42
+ described_class.post_with_time(*args)
43
+ end
44
+ end
45
+
46
+ describe "shortcut methods" do
47
+ let(:klass) { TreasureData }
48
+
49
+ describe ".logger" do
50
+ subject{ klass.logger }
51
+
52
+ it { is_expected.to eq TreasureData::Logger.logger }
53
+ end
54
+
55
+ describe ".open" do
56
+ let(:args) { ["tag", apikey: "dummy"] }
57
+
58
+ it "invoke TreasureData::Logger.open with args" do
59
+ expect(TreasureData::Logger).to receive(:open).with(*args)
60
+ klass.open(*args)
61
+ end
62
+ end
63
+
64
+ describe ".open_agent" do
65
+ let(:args) { ["tag", apikey: "dummy"] }
66
+
67
+ it "invoke TreasureData::Logger.open_agent with args" do
68
+ expect(TreasureData::Logger).to receive(:open_agent).with(*args)
69
+ klass.open_agent(*args)
70
+ end
71
+ end
72
+
73
+ describe ".open_null" do
74
+ it "invoke TreasureData::Logger.open_null" do
75
+ expect(TreasureData::Logger).to receive(:open_null).with(no_args)
76
+ klass.open_null
77
+ end
78
+ end
79
+
80
+ describe ".open_test" do
81
+ it "invoke TreasureData::Logger.open_test" do
82
+ expect(TreasureData::Logger).to receive(:open_test).with(no_args)
83
+ klass.open_test
84
+ end
85
+ end
86
+
87
+ describe ".post" do
88
+ let(:args) { ["tag", foo: "dummy"] }
89
+
90
+ it "invoke TreasureData::Logger.post with args" do
91
+ expect(TreasureData::Logger).to receive(:post).with(*args)
92
+ klass.post(*args)
93
+ end
94
+ end
95
+
96
+ describe ".post_with_time" do
97
+ let(:args) { ["tag", {foo: "dummy"}, Time.now] }
98
+
99
+ it "invoke TreasureData::Logger.post_with_time with args" do
100
+ expect(TreasureData::Logger).to receive(:post_with_time).with(*args)
101
+ klass.post_with_time(*args)
102
+ end
103
+ end
104
+
105
+ describe ".event" do
106
+ subject{ klass.event }
107
+
108
+ it { is_expected.to eq TreasureData::Logger.event }
109
+ end
110
+
111
+ describe ".log (backward compatibility)" do
112
+ let(:args) { ["tag", foo: "dummy"] }
113
+
114
+ it "invoke TreasureData::Logger.log with args" do
115
+ expect(TreasureData::Logger).to receive(:post).with(*args)
116
+ klass.log(*args)
117
+ end
118
+ end
119
+
120
+ describe "Event" do
121
+ it { expect(klass.const_get(:Event)).to eq TreasureData::Logger::Event }
122
+ end
123
+ end
124
+
125
+ it "define TD as TreasureData" do
126
+ expect(TD).to eq TreasureData
127
+ end
128
+ end
@@ -30,9 +30,11 @@ 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.4.4", "!= 0.5.0", "!= 0.5.1", "!= 0.5.2", "!= 0.5.3", "< 0.6.0"]
33
+ gem.add_dependency "msgpack", [">= 0.4.4", "!= 0.5.0", "!= 0.5.1", "!= 0.5.2", "!= 0.5.3", "< 0.8.0"]
34
34
  gem.add_dependency "td-client", "~> 0.8.66"
35
- gem.add_dependency "fluent-logger", "~> 0.4.9"
35
+ gem.add_dependency "fluent-logger", "~> 0.5.0"
36
36
  gem.add_development_dependency 'rake', '>= 0.9.2'
37
- gem.add_development_dependency 'rspec', '>= 2.7.0'
37
+ gem.add_development_dependency 'rspec', '~> 3.0'
38
+ gem.add_development_dependency 'coveralls'
39
+ gem.add_development_dependency 'rack'
38
40
  end
metadata CHANGED
@@ -1,128 +1,158 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.24
4
+ version: 0.3.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.4.4
20
- - - ! '!='
20
+ - - "!="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.5.0
23
- - - ! '!='
23
+ - - "!="
24
24
  - !ruby/object:Gem::Version
25
25
  version: 0.5.1
26
- - - ! '!='
26
+ - - "!="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 0.5.2
29
- - - ! '!='
29
+ - - "!="
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.5.3
32
- - - <
32
+ - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: 0.6.0
34
+ version: 0.8.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.4.4
42
- - - ! '!='
42
+ - - "!="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 0.5.0
45
- - - ! '!='
45
+ - - "!="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.5.1
48
- - - ! '!='
48
+ - - "!="
49
49
  - !ruby/object:Gem::Version
50
50
  version: 0.5.2
51
- - - ! '!='
51
+ - - "!="
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.5.3
54
- - - <
54
+ - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: 0.6.0
56
+ version: 0.8.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: td-client
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: 0.8.66
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: 0.8.66
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: fluent-logger
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ~>
75
+ - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: 0.4.9
77
+ version: 0.5.0
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ~>
82
+ - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: 0.4.9
84
+ version: 0.5.0
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rake
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ! '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: 0.9.2
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ! '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: 0.9.2
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: rspec
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ! '>='
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '3.0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '3.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: coveralls
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: rack
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
104
132
  - !ruby/object:Gem::Version
105
- version: 2.7.0
133
+ version: '0'
106
134
  type: :development
107
135
  prerelease: false
108
136
  version_requirements: !ruby/object:Gem::Requirement
109
137
  requirements:
110
- - - ! '>='
138
+ - - ">="
111
139
  - !ruby/object:Gem::Version
112
- version: 2.7.0
140
+ version: '0'
113
141
  description: Treasure Data logging library
114
142
  email:
115
143
  executables: []
116
144
  extensions: []
117
145
  extra_rdoc_files: []
118
146
  files:
119
- - .gitignore
120
- - .travis.yml
147
+ - ".coveralls.yml"
148
+ - ".gitignore"
149
+ - ".travis.yml"
121
150
  - ChangeLog
122
151
  - Gemfile
123
152
  - README.rdoc
124
153
  - Rakefile
125
154
  - VERSION
155
+ - appveyor.yml
126
156
  - config/heroku/treasure_data.yml
127
157
  - lib/td-logger.rb
128
158
  - lib/td/logger.rb
@@ -134,10 +164,13 @@ files:
134
164
  - lib/td/logger/event.rb
135
165
  - lib/td/logger/td_logger.rb
136
166
  - lib/td/logger/version.rb
137
- - spec/event_spec.rb
138
- - spec/rails_config_spec.rb
139
167
  - spec/spec_helper.rb
140
- - spec/td_logger_spec.rb
168
+ - spec/td/logger/agent/config_spec.rb
169
+ - spec/td/logger/agent/rack_spec.rb
170
+ - spec/td/logger/agent/rails_spec.rb
171
+ - spec/td/logger/event_spec.rb
172
+ - spec/td/logger/treasure_data_logger_spec.rb
173
+ - spec/td/logger_spec.rb
141
174
  - td-logger.gemspec
142
175
  homepage:
143
176
  licenses: []
@@ -148,22 +181,25 @@ require_paths:
148
181
  - lib
149
182
  required_ruby_version: !ruby/object:Gem::Requirement
150
183
  requirements:
151
- - - ! '>='
184
+ - - ">="
152
185
  - !ruby/object:Gem::Version
153
186
  version: '0'
154
187
  required_rubygems_version: !ruby/object:Gem::Requirement
155
188
  requirements:
156
- - - ! '>='
189
+ - - ">="
157
190
  - !ruby/object:Gem::Version
158
191
  version: '0'
159
192
  requirements: []
160
193
  rubyforge_project:
161
- rubygems_version: 2.2.2
194
+ rubygems_version: 2.4.5.1
162
195
  signing_key:
163
196
  specification_version: 4
164
197
  summary: Treasure Data logging library
165
198
  test_files:
166
- - spec/event_spec.rb
167
- - spec/rails_config_spec.rb
168
199
  - spec/spec_helper.rb
169
- - spec/td_logger_spec.rb
200
+ - spec/td/logger/agent/config_spec.rb
201
+ - spec/td/logger/agent/rack_spec.rb
202
+ - spec/td/logger/agent/rails_spec.rb
203
+ - spec/td/logger/event_spec.rb
204
+ - spec/td/logger/treasure_data_logger_spec.rb
205
+ - spec/td/logger_spec.rb
@@ -1,46 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
- describe TreasureData::Logger::Event do
5
- context 'preset' do
6
- let(:test_logger) do
7
- Fluent::Logger::TestLogger.new
8
- end
9
- before(:each) do
10
- t = test_logger
11
- TreasureData::Logger.module_eval do
12
- class_variable_set(:@@logger, t)
13
- end
14
- TD.event.attribute.clear
15
- end
16
-
17
- it 'action' do
18
- test_logger.should_receive(:post).with(:doit, {:action=>"doit", :foo=>:bar, :uid=>"uid1"}).twice
19
- TD.event.action(:doit, {:foo=>:bar}, "uid1")
20
- TD.event.attribute[:uid] = "uid1"
21
- TD.event.action(:doit, {:foo=>:bar})
22
- end
23
-
24
- it 'register' do
25
- test_logger.should_receive(:post).with(:register, {:action=>"register", :uid=>"uid1"}).twice
26
- TD.event.register("uid1")
27
- TD.event.attribute[:uid] = "uid1"
28
- TD.event.register
29
- end
30
-
31
- it 'login' do
32
- test_logger.should_receive(:post).with(:login, {:action=>"login", :uid=>"uid1"}).twice
33
- TD.event.login("uid1")
34
- TD.event.attribute[:uid] = "uid1"
35
- TD.event.login
36
- end
37
-
38
- it 'pay' do
39
- test_logger.should_receive(:post).with(:pay, {:action=>"pay", :category=>"cat", :sub_category=>"subcat", :name=>"name", :price=>1980, :count=>1, :uid=>"uid1"}).twice
40
- TD.event.pay("cat", "subcat", "name", 1980, 1, "uid1")
41
- TD.event.attribute[:uid] = "uid1"
42
- TD.event.pay("cat", "subcat", "name", 1980, 1)
43
- end
44
- end
45
- end
46
-
@@ -1,159 +0,0 @@
1
-
2
- require 'spec_helper'
3
- require 'fileutils'
4
- require 'logger'
5
-
6
- TMP_DIR = File.dirname(__FILE__) + "/tmp"
7
- FileUtils.rm_rf(TMP_DIR)
8
-
9
- class Rails
10
- def self.configuration
11
- self.new
12
- end
13
-
14
- def self.logger
15
- Logger.new(STDOUT)
16
- end
17
-
18
- def self.root
19
- TMP_DIR
20
- end
21
-
22
- def self.env
23
- "test"
24
- end
25
-
26
- def middleware
27
- self
28
- end
29
-
30
- def use(mod)
31
- end
32
- end
33
-
34
- class ActionController
35
- class Base
36
- end
37
- end
38
-
39
- class ActiveSupport
40
- class TimeWithZone
41
- end
42
- end
43
-
44
- require 'td/logger/agent/rails'
45
-
46
- describe TreasureData::Logger::Agent::Rails::Config do
47
- before(:each) do
48
- FileUtils.rm_rf(TMP_DIR)
49
- FileUtils.mkdir_p(TMP_DIR)
50
- ENV.delete('TREASURE_DATA_API_KEY')
51
- ENV.delete('TREASURE_DATA_DB')
52
- end
53
-
54
- context 'init' do
55
- it 'load_env' do
56
- ENV['TREASURE_DATA_API_KEY'] = 'test1'
57
- ENV['TREASURE_DATA_DB'] = 'db1'
58
- c = TreasureData::Logger::Agent::Rails::Config.init
59
- c.disabled.should == false
60
- c.agent_mode?.should == false
61
- c.apikey.should == 'test1'
62
- c.database.should == 'db1'
63
- c.auto_create_table.should == true
64
- end
65
-
66
- it 'load_file' do
67
- FileUtils.mkdir_p("#{TMP_DIR}/config")
68
- File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
69
- f.write <<EOF
70
- test:
71
- apikey: test2
72
- database: db2
73
- debug_mode: true
74
- EOF
75
- }
76
- c = TreasureData::Logger::Agent::Rails::Config.init
77
- c.disabled.should == false
78
- c.agent_mode?.should == false
79
- c.apikey.should == 'test2'
80
- c.database.should == 'db2'
81
- c.auto_create_table.should == true
82
- c.debug_mode.should == true
83
- end
84
-
85
- it 'load_file without test' do
86
- FileUtils.mkdir_p("#{TMP_DIR}/config")
87
- File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
88
- f.write <<EOF
89
- development:
90
- apikey: test2
91
- database: db2
92
- debug_mode: true
93
- EOF
94
- }
95
- c = TreasureData::Logger::Agent::Rails::Config.init
96
- c.disabled.should == true
97
- end
98
-
99
- it 'prefer file than env' do
100
- ENV['TREASURE_DATA_API_KEY'] = 'test3'
101
- ENV['TREASURE_DATA_DB'] = 'db3'
102
-
103
- FileUtils.mkdir_p("#{TMP_DIR}/config")
104
- File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
105
- f.write <<EOF
106
- test:
107
- apikey: test4
108
- database: db4
109
- auto_create_table: false
110
- EOF
111
- }
112
- c = TreasureData::Logger::Agent::Rails::Config.init
113
- c.disabled.should == false
114
- c.agent_mode?.should == false
115
- c.apikey.should == 'test4'
116
- c.database.should == 'db4'
117
- c.auto_create_table.should == false
118
- c.debug_mode.should == false
119
- end
120
-
121
- it 'agent mode' do
122
- FileUtils.mkdir_p("#{TMP_DIR}/config")
123
- File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
124
- f.write <<EOF
125
- test:
126
- agent: localhost
127
- tag: td.db5
128
- EOF
129
- }
130
- c = TreasureData::Logger::Agent::Rails::Config.init
131
- c.disabled.should == false
132
- c.agent_mode?.should == true
133
- c.tag.should == 'td.db5'
134
- c.agent_host.should == 'localhost'
135
- c.agent_port.should == 24224
136
- end
137
-
138
- it 'test mode' do
139
- FileUtils.mkdir_p("#{TMP_DIR}/config")
140
- File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
141
- f.write <<EOF
142
- test:
143
- agent: localhost
144
- tag: td.db5
145
- test_mode: true
146
- EOF
147
- }
148
- c = TreasureData::Logger::Agent::Rails::Config.init
149
- c.disabled.should == false
150
- c.test_mode?.should == true
151
- end
152
- end
153
- end
154
-
155
- describe ActiveSupport::TimeWithZone do
156
- it 'has to_msgpack' do
157
- ActiveSupport::TimeWithZone.method_defined?(:to_msgpack).should be_true
158
- end
159
- end