betterlog 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/betterlog.gemspec +2 -2
- data/config/log.yml +2 -2
- data/lib/betterlog/log.rb +11 -12
- data/lib/betterlog/version.rb +1 -1
- data/spec/betterlog/log_spec.rb +28 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 669ea0d62356d1741924aa51d8648fc8968cc32a910a9bcd96f88c90d91e494c
|
4
|
+
data.tar.gz: db1a0fb6aea128b0bff226bb912c0d66f0ba40b8955a854a1c6f02fb22e798f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a32f1c9ed9581edba4047bc14691a3a94653a553897b478361d012871ae2aa57843786642e41313c836f5fc5bf284153f5bc6bb49e734daf603d19d8cb70d37c
|
7
|
+
data.tar.gz: 56e67e0133c821f0f945328c0d3ddcacbf42503d4b0d21b2e4d454b52291bf95737c38493840828d8ceb308a6c6b1d8ca53c0b8abd17eccf3684511104692520
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.1
|
data/betterlog.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 0.8.
|
2
|
+
# stub: betterlog 0.8.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "betterlog".freeze
|
6
|
-
s.version = "0.8.
|
6
|
+
s.version = "0.8.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
data/config/log.yml
CHANGED
@@ -21,7 +21,7 @@ development: &development
|
|
21
21
|
timestamp: {%lt%timestamp}
|
22
22
|
severity: {severity}
|
23
23
|
message: "{message}"
|
24
|
-
metric: {metric} {value}
|
24
|
+
metric: {metric} {value}
|
25
25
|
error_class: {error_class}
|
26
26
|
backtrace: {%O%backtrace}
|
27
27
|
host: {host}
|
@@ -33,7 +33,7 @@ development: &development
|
|
33
33
|
{%0.1s%severity} [{%lt%timestamp} #{%d%pid}] {%5s%severity} --
|
34
34
|
{program}: {message}
|
35
35
|
metric: >
|
36
|
-
{%ft%timestamp} {metric} {value}
|
36
|
+
{%ft%timestamp} {metric} {value}
|
37
37
|
config_files:
|
38
38
|
rails:
|
39
39
|
- log/development.log
|
data/lib/betterlog/log.rb
CHANGED
@@ -83,19 +83,18 @@ module Betterlog
|
|
83
83
|
end
|
84
84
|
|
85
85
|
# Logs a metric on severity debug, by default, this can be changed by passing
|
86
|
-
# the severity: keyword. +name+ is for example 'Donation' and
|
87
|
-
#
|
88
|
-
#
|
86
|
+
# the severity: keyword. +name+ is for example 'Donation.Confirmation' and
|
87
|
+
# +value+ can be any value, but has to be somewhat consistent in terms of
|
88
|
+
# structure with +name+ to allow for correct
|
89
89
|
# evaluation.
|
90
90
|
#
|
91
91
|
# @param name the name of the recorded metric.
|
92
|
-
# @param type of the recorded metric.
|
93
92
|
# @param value of the recorded metric.
|
94
93
|
# @param **rest additional rest is logged as well.
|
95
94
|
# @return [ Log ] this object itself.
|
96
|
-
def metric(name:,
|
95
|
+
def metric(name:, value:, **rest)
|
97
96
|
protect do
|
98
|
-
event = build_metric(name: name,
|
97
|
+
event = build_metric(name: name, value: value, **rest)
|
99
98
|
emit event
|
100
99
|
end
|
101
100
|
end
|
@@ -120,7 +119,7 @@ module Betterlog
|
|
120
119
|
raise error
|
121
120
|
ensure
|
122
121
|
protect do
|
123
|
-
event = build_metric(name: name,
|
122
|
+
event = build_metric(name: name, value: timed_duration, **rest)
|
124
123
|
emit event
|
125
124
|
end
|
126
125
|
end
|
@@ -152,16 +151,16 @@ module Betterlog
|
|
152
151
|
self
|
153
152
|
end
|
154
153
|
|
155
|
-
def build_metric(name:,
|
156
|
-
severity = rest.fetch(:severity, :
|
154
|
+
def build_metric(name:, value:, **rest)
|
155
|
+
severity = rest.fetch(:severity, :info)
|
157
156
|
rest |= {
|
158
|
-
message: "a metric #{name}
|
157
|
+
message: "a metric #{name}=#{value}",
|
159
158
|
}
|
160
159
|
Log::Event.ify(
|
161
160
|
{
|
162
|
-
name:
|
163
|
-
type: type,
|
161
|
+
name: name,
|
164
162
|
value: value,
|
163
|
+
type: 'metric'
|
165
164
|
} | rest,
|
166
165
|
severity: severity
|
167
166
|
)
|
data/lib/betterlog/version.rb
CHANGED
data/spec/betterlog/log_spec.rb
CHANGED
@@ -140,11 +140,12 @@ describe Betterlog::Log do
|
|
140
140
|
|
141
141
|
it 'can be sent after measuring times' do
|
142
142
|
expected_event = Log::Event.new(
|
143
|
-
message:
|
144
|
-
name:
|
145
|
-
type: 'duration',
|
143
|
+
message: 'a metric foo=10.0',
|
144
|
+
name: 'foo',
|
146
145
|
value: 10.0,
|
147
|
-
timestamp: "2011-11-11T10:11:21.000Z"
|
146
|
+
timestamp: "2011-11-11T10:11:21.000Z",
|
147
|
+
type: 'metric',
|
148
|
+
severity: 'info'
|
148
149
|
)
|
149
150
|
expect(instance).to receive(:emit).with(expected_event)
|
150
151
|
Log.measure(name: 'foo') do
|
@@ -160,13 +161,14 @@ describe Betterlog::Log do
|
|
160
161
|
|
161
162
|
it 'adds exception information if block raises' do
|
162
163
|
expected_event = Log::Event.new(
|
163
|
-
name:
|
164
|
-
type: 'duration',
|
164
|
+
name: 'foo',
|
165
165
|
value: 3.0,
|
166
166
|
timestamp: "2011-11-11T10:11:14.000Z",
|
167
167
|
message: '"MyEx: we were fucked" while measuring metric foo',
|
168
168
|
error_class: 'MyEx',
|
169
|
-
backtrace: %w[ backtrace ]
|
169
|
+
backtrace: %w[ backtrace ],
|
170
|
+
type: 'metric',
|
171
|
+
severity: 'info'
|
170
172
|
)
|
171
173
|
expect(instance).to receive(:emit).with(expected_event)
|
172
174
|
raised = false
|
@@ -184,39 +186,41 @@ describe Betterlog::Log do
|
|
184
186
|
end
|
185
187
|
|
186
188
|
describe '#metric' do
|
187
|
-
it 'logs metrics with a specific structure on
|
189
|
+
it 'logs metrics with a specific structure on info log level' do
|
188
190
|
expected_event = Log::Event.new(
|
189
|
-
message:
|
190
|
-
name:
|
191
|
-
|
192
|
-
|
191
|
+
message: 'a metric controller.action=0.123',
|
192
|
+
name: 'controller.action',
|
193
|
+
value: 0.123,
|
194
|
+
type: 'metric',
|
195
|
+
severity: 'info'
|
193
196
|
)
|
194
197
|
expect(instance).to receive(:emit).with(expected_event)
|
195
|
-
Log.metric(name: 'controller.action',
|
198
|
+
Log.metric(name: 'controller.action', value: 0.123)
|
196
199
|
end
|
197
200
|
|
198
201
|
it 'logs metrics on a given log level' do
|
199
202
|
expected_event = Log::Event.new(
|
200
|
-
message:
|
201
|
-
name:
|
202
|
-
|
203
|
-
|
203
|
+
message: 'a metric controller.action=0.123',
|
204
|
+
name: 'controller.action',
|
205
|
+
value: 0.123,
|
206
|
+
type: 'metric',
|
204
207
|
severity: :info,
|
205
208
|
)
|
206
209
|
expect(instance).to receive(:emit).with(expected_event)
|
207
|
-
Log.metric(severity: :info, name: 'controller.action',
|
210
|
+
Log.metric(severity: :info, name: 'controller.action', value: 0.123)
|
208
211
|
end
|
209
212
|
|
210
213
|
it 'logs metrics with additional data' do
|
211
214
|
expected_event = Log::Event.new(
|
212
|
-
message:
|
213
|
-
foo:
|
214
|
-
name:
|
215
|
-
|
216
|
-
|
215
|
+
message: 'a metric controller.action=0.123',
|
216
|
+
foo: 'bar',
|
217
|
+
name: 'controller.action',
|
218
|
+
value: 0.123,
|
219
|
+
type: 'metric',
|
220
|
+
severity: 'info'
|
217
221
|
)
|
218
222
|
expect(instance).to receive(:emit).with(expected_event)
|
219
|
-
Log.metric(name: 'controller.action',
|
223
|
+
Log.metric(name: 'controller.action', value: 0.123, foo: 'bar')
|
220
224
|
end
|
221
225
|
end
|
222
226
|
end
|