act-fluent-logger-rails 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +19 -13
- data/lib/act-fluent-logger-rails/logger.rb +5 -2
- data/lib/act-fluent-logger-rails/version.rb +1 -1
- data/spec/logger_spec.rb +34 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3620e98091da97133d63c7988fd39d6fead83c5
|
4
|
+
data.tar.gz: e5be5d05fbe18db5facccd4cc6273bba08ba6e6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00ff02c7cc4536d5b1abd93184a6f632803ba73f71cb837b4aabd98ae4aa98b98c5e1f941c58f5ea66ada2f3a5e550c3131aaab3a60406a635e4c3f7e0692d99
|
7
|
+
data.tar.gz: 90b97b638e772f40cecfabe7c1de55b5134454b399c8da508a449ec56d8ee6a811d21023b555c3f05270f86c74e7c77a7358b7179195e7a174a2834139d958e2
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,46 +43,52 @@ Don't use config.log_tags.
|
|
43
43
|
fluent_port: 24224
|
44
44
|
tag: 'foo'
|
45
45
|
messages_type: 'string'
|
46
|
+
severity_key: 'level' # default severity
|
46
47
|
|
47
48
|
test:
|
48
49
|
fluent_host: '127.0.0.1'
|
49
50
|
fluent_port: 24224
|
50
51
|
tag: 'foo'
|
51
52
|
messages_type: 'string'
|
53
|
+
severity_key: 'level' # default severity
|
52
54
|
|
53
55
|
production:
|
54
56
|
fluent_host: '127.0.0.1'
|
55
57
|
fluent_port: 24224
|
56
58
|
tag: 'foo'
|
57
59
|
messages_type: 'string'
|
60
|
+
severity_key: 'level' # default severity
|
58
61
|
|
59
62
|
#### set an environment variable FLUENTD_URL
|
60
63
|
|
61
|
-
http://fluentd.example.com:42442/foo?messages_type=string
|
62
|
-
|
63
|
-
* fluent_host: The host name of Fluentd.
|
64
|
-
* fluent_port: The port number of Fluentd.
|
65
|
-
* tag: The tag of the Fluentd event.
|
66
|
-
* messages_type: The type of log messages. 'string' or 'array'.
|
64
|
+
http://fluentd.example.com:42442/foo?messages_type=string&severity_key=level
|
67
65
|
|
68
66
|
#### pass a settings object to ActFluentLoggerRails::Logger.new
|
69
67
|
|
70
68
|
config.logger = ActFluentLoggerRails::Logger.
|
71
69
|
new(settings: {
|
72
70
|
host: '127.0.0.1',
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
port: 24224,
|
72
|
+
tag: 'foo',
|
73
|
+
messages_type: 'string',
|
74
|
+
severity_key: 'level'
|
75
|
+
})
|
76
76
|
|
77
|
-
|
77
|
+
### Setting
|
78
|
+
|
79
|
+
* fluent_host: The host name of Fluentd.
|
80
|
+
* fluent_port: The port number of Fluentd.
|
81
|
+
* tag: The tag of the Fluentd event.
|
82
|
+
* messages_type: The type of log messages. 'string' or 'array'.
|
83
|
+
If it is 'string', the log messages is a String.
|
78
84
|
```
|
79
|
-
2013-01-18T15:04:50+09:00 foo {"messages":"Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900\nProcessing by TopController#index as HTML\nCompleted 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"
|
85
|
+
2013-01-18T15:04:50+09:00 foo {"messages":"Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900\nProcessing by TopController#index as HTML\nCompleted 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"severity":"INFO"}
|
80
86
|
```
|
81
87
|
If it is 'array', the log messages is an Array.
|
82
88
|
```
|
83
|
-
2013-01-18T15:04:50+09:00 foo {"messages":["Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900","Processing by TopController#index as HTML","Completed 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"
|
89
|
+
2013-01-18T15:04:50+09:00 foo {"messages":["Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900","Processing by TopController#index as HTML","Completed 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"severity":"INFO"}
|
84
90
|
```
|
85
|
-
|
91
|
+
* severity_key: The key of severity(DEBUG, INFO, WARN, ERROR).
|
86
92
|
|
87
93
|
You can add any tags at run time.
|
88
94
|
|
@@ -27,6 +27,7 @@ module ActFluentLoggerRails
|
|
27
27
|
host: fluent_config['fluent_host'],
|
28
28
|
port: fluent_config['fluent_port'],
|
29
29
|
messages_type: fluent_config['messages_type'],
|
30
|
+
severity_key: fluent_config['severity_key'],
|
30
31
|
}
|
31
32
|
end
|
32
33
|
|
@@ -46,7 +47,8 @@ module ActFluentLoggerRails
|
|
46
47
|
fluent_host: uri.host,
|
47
48
|
fluent_port: uri.port,
|
48
49
|
tag: uri.path[1..-1],
|
49
|
-
messages_type: params[
|
50
|
+
messages_type: params['messages_type'].try(:first),
|
51
|
+
severity_key: params['severity_key'].try(:first),
|
50
52
|
}.stringify_keys
|
51
53
|
end
|
52
54
|
|
@@ -65,6 +67,7 @@ module ActFluentLoggerRails
|
|
65
67
|
host = options[:host]
|
66
68
|
@messages_type = (options[:messages_type] || :array).to_sym
|
67
69
|
@tag = options[:tag]
|
70
|
+
@severity_key = (options[:severity_key] || :severity).to_sym
|
68
71
|
@flush_immediately = options[:flush_immediately]
|
69
72
|
@fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, host: host, port: port)
|
70
73
|
@severity = 0
|
@@ -120,7 +123,7 @@ module ActFluentLoggerRails
|
|
120
123
|
@messages
|
121
124
|
end
|
122
125
|
@map[:messages] = messages
|
123
|
-
@map[
|
126
|
+
@map[@severity_key] = format_severity(@severity)
|
124
127
|
@log_tags.each do |k, v|
|
125
128
|
@map[k] = case v
|
126
129
|
when Proc
|
data/spec/logger_spec.rb
CHANGED
@@ -57,7 +57,7 @@ EOF
|
|
57
57
|
expect(@my_logger.log).to eq([['foo', {
|
58
58
|
abc: 'xyz',
|
59
59
|
messages: ['hello'],
|
60
|
-
|
60
|
+
severity: 'INFO',
|
61
61
|
uuid: 'uuid_value',
|
62
62
|
foo: 'foo_value'
|
63
63
|
} ]])
|
@@ -65,7 +65,7 @@ EOF
|
|
65
65
|
logger.tagged([request]) { logger.info('world'); logger.info('bye') }
|
66
66
|
expect(@my_logger.log).to eq([['foo', {
|
67
67
|
messages: ['world', 'bye'],
|
68
|
-
|
68
|
+
severity: 'INFO',
|
69
69
|
uuid: 'uuid_value',
|
70
70
|
foo: 'foo_value'
|
71
71
|
} ]])
|
@@ -115,10 +115,40 @@ EOF
|
|
115
115
|
expect(@my_logger.log[0][1][:messages][0]).to eq(x.inspect)
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
describe 'severity_key' do
|
120
|
+
describe 'not specified' do
|
121
|
+
it 'severity' do
|
122
|
+
logger.tagged([request]) { logger.info('hello') }
|
123
|
+
expect(@my_logger.log[0][1][:severity]).to eq('INFO')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'severity_key: level' do
|
128
|
+
before do
|
129
|
+
@config_file = Tempfile.new('fluent-logger-config')
|
130
|
+
@config_file.close(false)
|
131
|
+
File.open(@config_file.path, 'w') {|f|
|
132
|
+
f.puts <<EOF
|
133
|
+
test:
|
134
|
+
fluent_host: '127.0.0.1'
|
135
|
+
fluent_port: 24224
|
136
|
+
tag: 'foo'
|
137
|
+
severity_key: 'level' # default severity
|
138
|
+
EOF
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'level' do
|
143
|
+
logger.tagged([request]) { logger.info('hello') }
|
144
|
+
expect(@my_logger.log[0][1][:level]).to eq('INFO')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
118
148
|
end
|
119
149
|
|
120
150
|
describe "use ENV['FLUENTD_URL']" do
|
121
|
-
let(:fluentd_url) { "http://fluentd.example.com:42442/hoge?messages_type=string" }
|
151
|
+
let(:fluentd_url) { "http://fluentd.example.com:42442/hoge?messages_type=string&severity_key=level" }
|
122
152
|
|
123
153
|
describe ".parse_url" do
|
124
154
|
subject { described_class.parse_url(fluentd_url) }
|
@@ -126,6 +156,7 @@ EOF
|
|
126
156
|
it { expect(subject['fluent_host']).to eq 'fluentd.example.com' }
|
127
157
|
it { expect(subject['fluent_port']).to eq 42442 }
|
128
158
|
it { expect(subject['messages_type']).to eq 'string' }
|
159
|
+
it { expect(subject['severity_key']).to eq 'level' }
|
129
160
|
end
|
130
161
|
end
|
131
162
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act-fluent-logger-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAHARA Yoshinori
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|