td-logger 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +6 -0
- data/README.rdoc +44 -7
- data/VERSION +1 -1
- data/lib/td/logger/agent/rails/config.rb +36 -1
- data/lib/td/logger/agent/rails.rb +2 -0
- data/lib/td/logger/td_logger.rb +7 -0
- data/lib/td/logger/version.rb +1 -1
- metadata +13 -23
data/ChangeLog
CHANGED
data/README.rdoc
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
= Treasure Data logging library for Rails
|
2
2
|
|
3
|
+
== About
|
4
|
+
|
5
|
+
This gem is a *logging* *library* *for* *Treasure* *Data*. The events logged by this module will be uploaded into the cloud. There're two ways to upload:
|
6
|
+
|
7
|
+
* 1) direct upload from applications: app -> cloud (used by default)
|
8
|
+
* 2) in-direct upload from td-agent: app -> td-agent -> cloud
|
9
|
+
|
10
|
+
(1) is more easy to configure and extra setup, but it requires extra memory in the application processes. (2) requires the extra installation of the daemons into your cluster, but lowers the logging impact to your applications. You can choose whether to use, by config file described laster.
|
11
|
+
|
3
12
|
== Getting Started
|
4
13
|
|
5
14
|
Add the following line to your Gemfile:
|
@@ -11,18 +20,17 @@ edit +environment.rb+ and add to the initalizer block:
|
|
11
20
|
|
12
21
|
config.gem "td-logger"
|
13
22
|
|
14
|
-
And then add +config/treasure_data.yml+ file as
|
23
|
+
And then add +config/treasure_data.yml+ file as followings. This is a template, which is doing the direct upload from the application processes.
|
15
24
|
|
16
|
-
# logging to Treasure Data directly
|
17
25
|
development:
|
18
26
|
apikey: "YOUR_API_KEY"
|
19
|
-
database:
|
27
|
+
database: rails_development
|
20
28
|
debug_mode: true # enable debug mode
|
21
29
|
|
22
|
-
# logging via td-agent (fluent)
|
23
30
|
production:
|
24
|
-
|
25
|
-
|
31
|
+
apikey: "YOUR_API_KEY"
|
32
|
+
database: rails_production
|
33
|
+
debug_mode: false
|
26
34
|
|
27
35
|
# disable logging
|
28
36
|
test:
|
@@ -56,9 +64,38 @@ In rails application, you can use 'TD.event.attribute' to set static attribute t
|
|
56
64
|
end
|
57
65
|
end
|
58
66
|
|
67
|
+
== Configuration file
|
68
|
+
|
69
|
+
=== Direct Upload from Application Buffer
|
70
|
+
|
71
|
+
This configuration enables the application to upload the events, directly from the application processes (app -> cloud).
|
72
|
+
|
73
|
+
production:
|
74
|
+
apikey: "YOUR_API_KEY"
|
75
|
+
database: rails_production
|
76
|
+
debug_mode: false
|
77
|
+
|
78
|
+
=== In-Direct Upload from td-agent
|
79
|
+
|
80
|
+
When 'agent' and 'tag' options are specified, the events are logged into the local td-agent daemon. Later on, the daemon uploads the event periodically to the cloud (app -> td-agent -> cloud).
|
81
|
+
|
82
|
+
This requires the additional setup to your infrastructure, but lowers the memory and performance impact to your application processes. For the installation process, please look at our {knowledge base}[http://help.treasure-data.com/kb/installing-td-agent-daemon] page.
|
83
|
+
|
84
|
+
NOTE: This configuration is not supported on PaaP platforms.
|
85
|
+
|
86
|
+
production:
|
87
|
+
agent: "localhost:24224"
|
88
|
+
tag: td.myapp
|
89
|
+
debug_mode: false
|
90
|
+
|
91
|
+
== Further Readings
|
92
|
+
|
93
|
+
If you have any problem, please ask us from the support site.
|
94
|
+
|
95
|
+
* {Support Site}[http://help.treasure-data.com/]
|
96
|
+
* {Knowledge Base}[http://help.treasure-data.com/kb]
|
59
97
|
|
60
98
|
== Copyright
|
61
99
|
|
62
100
|
Copyright:: Copyright (c) 2011 Treasure Data Inc.
|
63
101
|
License:: Apache License, Version 2.0
|
64
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
@@ -50,7 +50,13 @@ module Agent::Rails
|
|
50
50
|
if File.exist?("#{::Rails.root}/#{CONFIG_PATH}")
|
51
51
|
load_file(logger)
|
52
52
|
else
|
53
|
-
|
53
|
+
if File.exist?("#{::Rails.root}/#{CONFIG_PATH_EY_DEPLOY}")
|
54
|
+
load_file_ey(logger, "#{::Rails.root}/#{CONFIG_PATH_EY_DEPLOY}")
|
55
|
+
elsif File.exist?("#{::Rails.root}/#{CONFIG_PATH_EY_LOCAL}")
|
56
|
+
load_file_ey(logger, "#{::Rails.root}/#{CONFIG_PATH_EY_LOCAL}")
|
57
|
+
else
|
58
|
+
load_env(logger)
|
59
|
+
end
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
@@ -84,6 +90,35 @@ module Agent::Rails
|
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
93
|
+
def self.load_file_ey(logger, path)
|
94
|
+
require 'yaml'
|
95
|
+
require 'erb'
|
96
|
+
|
97
|
+
begin
|
98
|
+
src = File.read(path)
|
99
|
+
yaml = ERB.new(src).result
|
100
|
+
env_conf = YAML.load(yaml)
|
101
|
+
rescue
|
102
|
+
logger.warn "WARNING: Can't load #{path} file: #{$!}"
|
103
|
+
logger.warn "WARNING: Disabling Treasure Data event logger."
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
|
107
|
+
apikey = env_conf['td']['TREASURE_DATA_API_KEY'] if env_conf.is_a?(Hash)
|
108
|
+
unless apikey
|
109
|
+
logger.warn "WARNING: #{path} does not exist."
|
110
|
+
logger.warn "WARNING: Disabling Treasure Data event logger."
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
return Config.new({
|
115
|
+
'apikey' => apikey,
|
116
|
+
'database' => ENV['TREASURE_DATA_DB'] || "rails_#{::Rails.env}",
|
117
|
+
'access_log_table' => ENV['TREASURE_DATA_ACCESS_LOG_TABLE'],
|
118
|
+
'auto_create_table' => true
|
119
|
+
})
|
120
|
+
end
|
121
|
+
|
87
122
|
def self.load_env(logger)
|
88
123
|
apikey = ENV['TREASURE_DATA_API_KEY'] || ENV['TD_API_KEY']
|
89
124
|
|
@@ -3,6 +3,8 @@ module Logger
|
|
3
3
|
module Agent::Rails
|
4
4
|
|
5
5
|
CONFIG_PATH = 'config/treasure_data.yml'
|
6
|
+
CONFIG_PATH_EY_LOCAL = 'config/ey_services_config_local.yml'
|
7
|
+
CONFIG_PATH_EY_DEPLOY = 'config/ey_services_config_deploy.yml'
|
6
8
|
|
7
9
|
require 'td/logger/agent/rack'
|
8
10
|
require 'td/logger/agent/rails/config'
|
data/lib/td/logger/td_logger.rb
CHANGED
@@ -64,6 +64,8 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
64
64
|
@queue = []
|
65
65
|
|
66
66
|
@chunk_limit = 8*1024*1024
|
67
|
+
@queue_limit = 50
|
68
|
+
|
67
69
|
@flush_interval = 10
|
68
70
|
@max_flush_interval = 300
|
69
71
|
@retry_wait = 1.0
|
@@ -179,6 +181,11 @@ class TreasureDataLogger < Fluent::Logger::LoggerBase
|
|
179
181
|
key = [db, table]
|
180
182
|
|
181
183
|
@mutex.synchronize do
|
184
|
+
if @queue.length > @queue_limit
|
185
|
+
@logger.error("TreasureDataLogger: queue length exceeds limit. can't add new event log: #{msg.inspect}")
|
186
|
+
return false
|
187
|
+
end
|
188
|
+
|
182
189
|
buffer = (@map[key] ||= '')
|
183
190
|
|
184
191
|
buffer << data
|
data/lib/td/logger/version.rb
CHANGED
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.8
|
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:
|
12
|
+
date: 2012-02-24 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: msgpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &20688200 !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: *20688200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: td-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &20686380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.8.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20686380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fluent-logger
|
38
|
-
requirement: &
|
38
|
+
requirement: &20685280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.4.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20685280
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &20684180 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *20684180
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &20630960 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 2.7.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *20630960
|
69
69
|
description: Treasure Data logging library for Rails
|
70
70
|
email:
|
71
71
|
executables: []
|
@@ -105,26 +105,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- - ! '>='
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: -1557178488144164455
|
111
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
109
|
none: false
|
113
110
|
requirements:
|
114
111
|
- - ! '>='
|
115
112
|
- !ruby/object:Gem::Version
|
116
113
|
version: '0'
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
hash: -1557178488144164455
|
120
114
|
requirements: []
|
121
115
|
rubyforge_project:
|
122
116
|
rubygems_version: 1.8.10
|
123
117
|
signing_key:
|
124
118
|
specification_version: 3
|
125
119
|
summary: Treasure Data logging library for Rails
|
126
|
-
test_files:
|
127
|
-
- spec/event_spec.rb
|
128
|
-
- spec/rails_config_spec.rb
|
129
|
-
- spec/spec_helper.rb
|
130
|
-
- spec/td_logger_spec.rb
|
120
|
+
test_files: []
|