td-logger 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/lib/td/logger/event.rb +1 -1
- data/lib/td/logger/version.rb +1 -1
- data/spec/event_spec.rb +44 -0
- data/spec/rails_config_spec.rb +116 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/td_logger_spec.rb +21 -0
- metadata +17 -9
data/ChangeLog
CHANGED
data/lib/td/logger/event.rb
CHANGED
@@ -12,7 +12,7 @@ module Logger
|
|
12
12
|
unless uid
|
13
13
|
raise ArgumentError, "wrong number of arguments (2 for 3): :uid attribute is required"
|
14
14
|
end
|
15
|
-
post(name, record.merge({:uid=>uid}))
|
15
|
+
post(name, record.merge({:action=>name.to_s, :uid=>uid}))
|
16
16
|
end
|
17
17
|
|
18
18
|
def register(uid=TD.event.attribute[:uid])
|
data/lib/td/logger/version.rb
CHANGED
data/spec/event_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
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.class_variable_set(:@@logger, t)
|
12
|
+
TD.event.attribute.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'action' do
|
16
|
+
test_logger.should_receive(:post).with(:doit, {:action=>"doit", :foo=>:bar, :uid=>"uid1"}).twice
|
17
|
+
TD.event.action(:doit, {:foo=>:bar}, "uid1")
|
18
|
+
TD.event.attribute[:uid] = "uid1"
|
19
|
+
TD.event.action(:doit, {:foo=>:bar})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'register' do
|
23
|
+
test_logger.should_receive(:post).with(:register, {:action=>"register", :uid=>"uid1"}).twice
|
24
|
+
TD.event.register("uid1")
|
25
|
+
TD.event.attribute[:uid] = "uid1"
|
26
|
+
TD.event.register
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'login' do
|
30
|
+
test_logger.should_receive(:post).with(:login, {:action=>"login", :uid=>"uid1"}).twice
|
31
|
+
TD.event.login("uid1")
|
32
|
+
TD.event.attribute[:uid] = "uid1"
|
33
|
+
TD.event.login
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'pay' do
|
37
|
+
test_logger.should_receive(:post).with(:pay, {:action=>"pay", :category=>"cat", :sub_category=>"subcat", :name=>"name", :price=>1980, :count=>1, :uid=>"uid1"}).twice
|
38
|
+
TD.event.pay("cat", "subcat", "name", 1980, 1, "uid1")
|
39
|
+
TD.event.attribute[:uid] = "uid1"
|
40
|
+
TD.event.pay("cat", "subcat", "name", 1980, 1)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,116 @@
|
|
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
|
+
require 'td/logger/agent/rails'
|
40
|
+
|
41
|
+
describe TreasureData::Logger::Agent::Rails::Config do
|
42
|
+
before(:each) do
|
43
|
+
FileUtils.rm_rf(TMP_DIR)
|
44
|
+
FileUtils.mkdir_p(TMP_DIR)
|
45
|
+
ENV.delete('TREASURE_DATA_API_KEY')
|
46
|
+
ENV.delete('TREASURE_DATA_DB')
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'init' do
|
50
|
+
it 'load_env' do
|
51
|
+
ENV['TREASURE_DATA_API_KEY'] = 'test1'
|
52
|
+
ENV['TREASURE_DATA_DB'] = 'db1'
|
53
|
+
c = TreasureData::Logger::Agent::Rails::Config.init
|
54
|
+
c.agent_mode?.should == false
|
55
|
+
c.apikey.should == 'test1'
|
56
|
+
c.database.should == 'db1'
|
57
|
+
c.auto_create_table.should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'load_file' do
|
61
|
+
FileUtils.mkdir_p("#{TMP_DIR}/config")
|
62
|
+
File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
|
63
|
+
f.write <<EOF
|
64
|
+
test:
|
65
|
+
apikey: test2
|
66
|
+
database: db2
|
67
|
+
debug_mode: true
|
68
|
+
EOF
|
69
|
+
}
|
70
|
+
c = TreasureData::Logger::Agent::Rails::Config.init
|
71
|
+
c.agent_mode?.should == false
|
72
|
+
c.apikey.should == 'test2'
|
73
|
+
c.database.should == 'db2'
|
74
|
+
c.auto_create_table.should == true
|
75
|
+
c.debug_mode.should == true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'prefer file than env' do
|
79
|
+
ENV['TREASURE_DATA_API_KEY'] = 'test3'
|
80
|
+
ENV['TREASURE_DATA_DB'] = 'db3'
|
81
|
+
|
82
|
+
FileUtils.mkdir_p("#{TMP_DIR}/config")
|
83
|
+
File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
|
84
|
+
f.write <<EOF
|
85
|
+
test:
|
86
|
+
apikey: test4
|
87
|
+
database: db4
|
88
|
+
auto_create_table: false
|
89
|
+
EOF
|
90
|
+
}
|
91
|
+
c = TreasureData::Logger::Agent::Rails::Config.init
|
92
|
+
c.agent_mode?.should == false
|
93
|
+
c.apikey.should == 'test4'
|
94
|
+
c.database.should == 'db4'
|
95
|
+
c.auto_create_table.should == false
|
96
|
+
c.debug_mode.should == false
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'agent mode' do
|
100
|
+
FileUtils.mkdir_p("#{TMP_DIR}/config")
|
101
|
+
File.open("#{TMP_DIR}/config/treasure_data.yml", "w") {|f|
|
102
|
+
f.write <<EOF
|
103
|
+
test:
|
104
|
+
agent: localhost
|
105
|
+
tag: td.db5
|
106
|
+
EOF
|
107
|
+
}
|
108
|
+
c = TreasureData::Logger::Agent::Rails::Config.init
|
109
|
+
c.agent_mode?.should == true
|
110
|
+
c.tag.should == 'td.db5'
|
111
|
+
c.agent_host.should == 'localhost'
|
112
|
+
c.agent_port.should == 24224
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'td-logger'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
#config.filter_run :focus => true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
|
10
|
+
config.mock_with :rspec
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TreasureData::Logger::TreasureDataLogger do
|
5
|
+
context 'init' do
|
6
|
+
it 'db config' do
|
7
|
+
td = TreasureData::Logger::TreasureDataLogger.new('db1', :apikey=>'test')
|
8
|
+
time = Time.now
|
9
|
+
td.should_receive(:add).with('db1', 'table1', {:foo=>:bar, :time=>time.to_i})
|
10
|
+
td.post_with_time('table1', {:foo=>:bar}, time)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'fluent-logger-td compat' do
|
14
|
+
td = TreasureData::Logger::TreasureDataLogger.new('db1', :apikey=>'test')
|
15
|
+
time = Time.now
|
16
|
+
td.should_receive(:add).with('overwrite', 'table1', {:foo=>:bar, :time=>time.to_i})
|
17
|
+
td.post_with_time('overwrite.table1', {:foo=>:bar}, time)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: td-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.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-
|
12
|
+
date: 2011-11-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70322049770860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70322049770860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: td-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70322049768540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70322049768540
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fluent-logger
|
38
|
-
requirement: &
|
38
|
+
requirement: &70322049767320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.4.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70322049767320
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
executables: []
|
@@ -62,6 +62,10 @@ files:
|
|
62
62
|
- lib/td/logger/event.rb
|
63
63
|
- lib/td/logger/td_logger.rb
|
64
64
|
- lib/td/logger/version.rb
|
65
|
+
- spec/event_spec.rb
|
66
|
+
- spec/rails_config_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/td_logger_spec.rb
|
65
69
|
- ChangeLog
|
66
70
|
- README.rdoc
|
67
71
|
homepage:
|
@@ -88,4 +92,8 @@ rubygems_version: 1.8.10
|
|
88
92
|
signing_key:
|
89
93
|
specification_version: 3
|
90
94
|
summary: Treasure Data logging library for Rails
|
91
|
-
test_files:
|
95
|
+
test_files:
|
96
|
+
- spec/event_spec.rb
|
97
|
+
- spec/rails_config_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/td_logger_spec.rb
|