betterlog 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/betterlog.gemspec +3 -3
- data/bin/betterlog +18 -12
- data/cloudbuild.yaml +2 -2
- data/go.mod +4 -3
- data/go.sum +9 -6
- data/lib/betterlog/log.rb +15 -25
- data/lib/betterlog/version.rb +1 -1
- data/spec/betterlog/log_spec.rb +42 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93ac0b92fff87f8005af14b59044b35a17981c2fd30ca1a3614d52967cf711b8
|
4
|
+
data.tar.gz: 22756efdebaa24185c28ffa2ba76cec177e83177f94b874d4bac13c3d8d87ac5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f4313920141cf7b4549da03362eb1ac585a8ac6f8d6bd80bc95cbff178797f507267ae9c9b56ab2423271c0a69dc5e9c3f0cb4c8454c7ff6824530ede26c8d
|
7
|
+
data.tar.gz: 2626a52f7915d4a2699cfcbde0425a736e5c41d1fefb03e13adefaa44961f1f118ac44921f37f34fe9adb7a65b3ee03b145d3cb331e9ca7ac4e6909ca1a45097
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
data/betterlog.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 0.
|
2
|
+
# stub: betterlog 0.11.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "betterlog".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.11.0"
|
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]
|
10
10
|
s.authors = ["betterplace Developers".freeze]
|
11
|
-
s.date = "2020-
|
11
|
+
s.date = "2020-04-02"
|
12
12
|
s.description = "This library provides structure json logging for our rails projects".freeze
|
13
13
|
s.email = "developers@betterplace.org".freeze
|
14
14
|
s.executables = ["betterlog".freeze, "betterlog_pusher".freeze, "betterlog_sink".freeze]
|
data/bin/betterlog
CHANGED
@@ -27,12 +27,12 @@ module Betterlog
|
|
27
27
|
-h to display this help
|
28
28
|
-p FORMAT to pretty print the log file if possible
|
29
29
|
-e EMITTER only output events from these emitters
|
30
|
-
-s MATCH only display events matching this search string
|
30
|
+
-s MATCH only display events matching this search string (can be repeated)
|
31
31
|
-S SEVERITY only output events with severity, e. g. -S '>=warn'
|
32
32
|
-n NUMBER rewind this many lines backwards before tailing log file
|
33
33
|
-F SHORTCUT to open the config files with SHORTCUT
|
34
34
|
|
35
|
-
FORMAT values are: #{Array(cc.log.formats?&.attribute_names) * ?,}
|
35
|
+
FORMAT values are: #{(Array(cc.log.formats?&.attribute_names) + %w[j json]) * ?,}
|
36
36
|
|
37
37
|
SEVERITY values are: #{Log::Severity.all * ?|}
|
38
38
|
|
@@ -93,15 +93,18 @@ module Betterlog
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def search_matched?(event)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
return true unless @opts[?s]
|
97
|
+
@opts[?s].all? do |param|
|
98
|
+
case param
|
99
|
+
when /:\?\z/
|
100
|
+
event[$`].present?
|
101
|
+
when /:([^:]+)\z/
|
102
|
+
event[$`].full?(:include?, $1)
|
103
|
+
when String
|
104
|
+
event.to_json.include?(@opts[?s])
|
105
|
+
else
|
106
|
+
return true
|
107
|
+
end
|
105
108
|
end
|
106
109
|
end
|
107
110
|
|
@@ -109,7 +112,10 @@ module Betterlog
|
|
109
112
|
return unless @severities.include?(event.severity)
|
110
113
|
return if emitters.full? && !emitters.include?(event.emitter)
|
111
114
|
search_matched?(event) or return
|
112
|
-
|
115
|
+
format = @opts[?p]&.to_sym
|
116
|
+
if format == :json || format == :j
|
117
|
+
puts event.format(pretty: false, color: @opts[?c])
|
118
|
+
elsif format
|
113
119
|
puts event.format(pretty: :format, color: @opts[?c], format: format)
|
114
120
|
else
|
115
121
|
puts "#{prefix}#{event}"
|
data/cloudbuild.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
steps:
|
2
|
-
- name: gcr.io/
|
2
|
+
- name: eu.gcr.io/betterplace-183212/better-builder
|
3
3
|
args: ['pull', '${_BASE_IMAGE}']
|
4
|
-
- name: gcr.io/
|
4
|
+
- name: eu.gcr.io/betterplace-183212/better-builder
|
5
5
|
args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}', '--build-arg=BASE_IMAGE=${_BASE_IMAGE}', '.']
|
6
6
|
images:
|
7
7
|
- 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA'
|
data/go.mod
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module github.com/betterplace/betterlog
|
2
2
|
|
3
|
-
go 1.
|
3
|
+
go 1.14
|
4
4
|
|
5
5
|
require (
|
6
6
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
7
|
-
github.com/go-redis/redis v6.15.
|
7
|
+
github.com/go-redis/redis v6.15.7+incompatible
|
8
8
|
github.com/kelseyhightower/envconfig v1.4.0 // indirect
|
9
9
|
github.com/labstack/echo v3.3.10+incompatible
|
10
10
|
github.com/labstack/gommon v0.3.0 // indirect
|
11
|
-
|
11
|
+
github.com/valyala/fasttemplate v1.1.0 // indirect
|
12
|
+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
|
12
13
|
)
|
data/go.sum
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
2
|
+
github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM=
|
2
3
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
3
4
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
4
|
-
github.com/go-redis/redis v6.15.
|
5
|
-
github.com/go-redis/redis v6.15.
|
5
|
+
github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
|
6
|
+
github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
6
7
|
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
7
8
|
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
9
|
+
github.com/labstack/echo v1.4.4 h1:1bEiBNeGSUKxcPDGfZ/7IgdhJJZx8wV/pICJh4W2NJI=
|
8
10
|
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
|
9
11
|
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
10
12
|
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
|
@@ -19,17 +21,18 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|
19
21
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
20
22
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
21
23
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
22
|
-
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
23
24
|
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
25
|
+
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
|
26
|
+
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
24
27
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
25
|
-
golang.org/x/crypto v0.0.0-
|
26
|
-
golang.org/x/crypto v0.0.0-
|
28
|
+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
|
29
|
+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
27
30
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
28
31
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
29
32
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
30
33
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
34
|
+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
31
35
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
32
|
-
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
33
36
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
34
37
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
35
38
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
data/lib/betterlog/log.rb
CHANGED
@@ -89,29 +89,11 @@ module Betterlog
|
|
89
89
|
# evaluation.
|
90
90
|
#
|
91
91
|
# @param name the name of the recorded metric.
|
92
|
-
# @param value of the recorded metric.
|
92
|
+
# @param value of the recorded metric, defaults to duration if block was given.
|
93
93
|
# @param **rest additional rest is logged as well.
|
94
94
|
# @return [ Log ] this object itself.
|
95
|
-
def metric(name:, value
|
96
|
-
|
97
|
-
event = build_metric(name: name, value: value, **rest)
|
98
|
-
emit event
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Logs a time measure on severity debug, by default, this can be changed by
|
103
|
-
# passing the severity: keyword.
|
104
|
-
#
|
105
|
-
# If an error occurs during measurement details about it are added to the
|
106
|
-
# metric event.
|
107
|
-
#
|
108
|
-
# @param name the name of the recorded metric.
|
109
|
-
# @param **rest additional rest is logged as well.
|
110
|
-
# @param block the block around which the measure is teaken.
|
111
|
-
# @return [ Log ] this object itself.
|
112
|
-
def measure(name:, **rest, &block)
|
113
|
-
raise ArgumentError, 'must be called with a block' unless block_given?
|
114
|
-
time_block { yield }
|
95
|
+
def metric(name:, value: nil, **rest, &block)
|
96
|
+
time_block(&block)
|
115
97
|
rescue => error
|
116
98
|
e = Log::Event.ify(error)
|
117
99
|
rest |= e.as_hash.subhash(:error_class, :backtrace, :message)
|
@@ -119,7 +101,14 @@ module Betterlog
|
|
119
101
|
raise error
|
120
102
|
ensure
|
121
103
|
protect do
|
122
|
-
|
104
|
+
if timed_duration
|
105
|
+
rest[:duration] = timed_duration
|
106
|
+
end
|
107
|
+
event = build_metric(
|
108
|
+
name: name,
|
109
|
+
value: value || timed_duration,
|
110
|
+
**rest
|
111
|
+
)
|
123
112
|
emit event
|
124
113
|
end
|
125
114
|
end
|
@@ -190,11 +179,12 @@ module Betterlog
|
|
190
179
|
|
191
180
|
thread_local :timed_duration
|
192
181
|
|
193
|
-
def time_block
|
182
|
+
def time_block(&block)
|
183
|
+
block or return
|
194
184
|
s = Time.now
|
195
|
-
|
185
|
+
block.call
|
196
186
|
ensure
|
197
|
-
self.timed_duration = Time.now - s
|
187
|
+
block and self.timed_duration = Time.now - s
|
198
188
|
end
|
199
189
|
end
|
200
190
|
end
|
data/lib/betterlog/version.rb
CHANGED
data/spec/betterlog/log_spec.rb
CHANGED
@@ -137,22 +137,60 @@ describe Betterlog::Log do
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
-
describe '#
|
140
|
+
describe '#metric' do
|
141
141
|
after do
|
142
142
|
Time.dummy = nil
|
143
143
|
end
|
144
144
|
|
145
|
+
it 'logs metrics with a specific structure on info log level' do
|
146
|
+
expected_event = Log::Event.new(
|
147
|
+
message: 'a metric controller.action=0.123',
|
148
|
+
name: 'controller.action',
|
149
|
+
value: 0.123,
|
150
|
+
type: 'metric',
|
151
|
+
severity: 'info'
|
152
|
+
)
|
153
|
+
expect(instance).to receive(:emit).with(expected_event)
|
154
|
+
Log.metric(name: 'controller.action', value: 0.123)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'logs metrics on a given log level' do
|
158
|
+
expected_event = Log::Event.new(
|
159
|
+
message: 'a metric controller.action=0.123',
|
160
|
+
name: 'controller.action',
|
161
|
+
value: 0.123,
|
162
|
+
type: 'metric',
|
163
|
+
severity: :info,
|
164
|
+
)
|
165
|
+
expect(instance).to receive(:emit).with(expected_event)
|
166
|
+
Log.metric(severity: :info, name: 'controller.action', value: 0.123)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'logs metrics with additional data' do
|
170
|
+
expected_event = Log::Event.new(
|
171
|
+
message: 'a metric controller.action=0.123',
|
172
|
+
foo: 'bar',
|
173
|
+
name: 'controller.action',
|
174
|
+
value: 0.123,
|
175
|
+
type: 'metric',
|
176
|
+
severity: 'info'
|
177
|
+
)
|
178
|
+
expect(instance).to receive(:emit).with(expected_event)
|
179
|
+
Log.metric(name: 'controller.action', value: 0.123, foo: 'bar')
|
180
|
+
end
|
181
|
+
|
145
182
|
it 'can be sent after measuring times' do
|
146
183
|
expected_event = Log::Event.new(
|
147
184
|
message: 'a metric foo=10.0',
|
148
185
|
name: 'foo',
|
149
186
|
value: 10.0,
|
187
|
+
duration: 10.0,
|
150
188
|
timestamp: "2011-11-11T10:11:21.000Z",
|
151
189
|
type: 'metric',
|
152
190
|
severity: 'info'
|
153
191
|
)
|
154
192
|
expect(instance).to receive(:emit).with(expected_event)
|
155
|
-
Log.
|
193
|
+
Log.metric(name: 'foo') do
|
156
194
|
Time.dummy = Time.now + 10
|
157
195
|
end
|
158
196
|
end
|
@@ -167,6 +205,7 @@ describe Betterlog::Log do
|
|
167
205
|
expected_event = Log::Event.new(
|
168
206
|
name: 'foo',
|
169
207
|
value: 3.0,
|
208
|
+
duration: 3.0,
|
170
209
|
timestamp: "2011-11-11T10:11:14.000Z",
|
171
210
|
message: '"MyEx: we were fucked" while measuring metric foo',
|
172
211
|
error_class: 'MyEx',
|
@@ -177,7 +216,7 @@ describe Betterlog::Log do
|
|
177
216
|
expect(instance).to receive(:emit).with(expected_event)
|
178
217
|
raised = false
|
179
218
|
begin
|
180
|
-
Log.
|
219
|
+
Log.metric(name: 'foo') do
|
181
220
|
Time.dummy = Time.now + 3
|
182
221
|
raise MyEx, "we were fucked"
|
183
222
|
Time.dummy = Time.now + 7
|
@@ -187,44 +226,6 @@ describe Betterlog::Log do
|
|
187
226
|
end
|
188
227
|
expect(raised).to eq true
|
189
228
|
end
|
190
|
-
end
|
191
|
-
|
192
|
-
describe '#metric' do
|
193
|
-
it 'logs metrics with a specific structure on info log level' do
|
194
|
-
expected_event = Log::Event.new(
|
195
|
-
message: 'a metric controller.action=0.123',
|
196
|
-
name: 'controller.action',
|
197
|
-
value: 0.123,
|
198
|
-
type: 'metric',
|
199
|
-
severity: 'info'
|
200
|
-
)
|
201
|
-
expect(instance).to receive(:emit).with(expected_event)
|
202
|
-
Log.metric(name: 'controller.action', value: 0.123)
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'logs metrics on a given log level' do
|
206
|
-
expected_event = Log::Event.new(
|
207
|
-
message: 'a metric controller.action=0.123',
|
208
|
-
name: 'controller.action',
|
209
|
-
value: 0.123,
|
210
|
-
type: 'metric',
|
211
|
-
severity: :info,
|
212
|
-
)
|
213
|
-
expect(instance).to receive(:emit).with(expected_event)
|
214
|
-
Log.metric(severity: :info, name: 'controller.action', value: 0.123)
|
215
|
-
end
|
216
229
|
|
217
|
-
it 'logs metrics with additional data' do
|
218
|
-
expected_event = Log::Event.new(
|
219
|
-
message: 'a metric controller.action=0.123',
|
220
|
-
foo: 'bar',
|
221
|
-
name: 'controller.action',
|
222
|
-
value: 0.123,
|
223
|
-
type: 'metric',
|
224
|
-
severity: 'info'
|
225
|
-
)
|
226
|
-
expect(instance).to receive(:emit).with(expected_event)
|
227
|
-
Log.metric(name: 'controller.action', value: 0.123, foo: 'bar')
|
228
|
-
end
|
229
230
|
end
|
230
231
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betterlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|