betterlog 0.11.0 → 0.13.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/Dockerfile +2 -4
- data/Makefile +4 -8
- data/VERSION +1 -1
- data/betterlog.gemspec +3 -3
- data/bin/betterlog_sink +3 -3
- data/cloudbuild.yaml +1 -3
- data/lib/betterlog/log.rb +21 -18
- data/lib/betterlog/log/event.rb +2 -2
- data/lib/betterlog/log/event_formatter.rb +2 -1
- data/lib/betterlog/logger.rb +1 -1
- data/lib/betterlog/notifiers.rb +1 -1
- data/lib/betterlog/version.rb +1 -1
- data/spec/betterlog/log/event_spec.rb +2 -2
- data/spec/betterlog/log_spec.rb +9 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29fe6dd6fca5b0294e9f55388615d6d8b58885a2f1898682525d19f239bd4552
|
4
|
+
data.tar.gz: f5495f46f7a6473edbe7a1e4973f9ac021213eb121dd149f5b50d23d191ab9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1345db77124853df14e65a3bfb5680b7936de5711cc0f21449d172822e8f44981a500b03cc29a072781039e4692cfc544e63387d817fa1eb65c4ea55995d83c3
|
7
|
+
data.tar.gz: f63ed3284d529d6df4f76f3e885d1c52d6d7dbba024ee08c61fcce8e79e0b8f3e04c1a4d15c7c7de7f017568a3ffea0c0cdd9c4da7f649b38172317abf735a09
|
data/Dockerfile
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
FROM ${BASE_IMAGE} AS builder
|
1
|
+
FROM alpine:3.12.0 AS builder
|
4
2
|
|
5
3
|
# Update/Upgrade/Add packages for building
|
6
4
|
|
@@ -20,7 +18,7 @@ RUN go get -u github.com/betterplace/go-init
|
|
20
18
|
|
21
19
|
RUN make fetch all
|
22
20
|
|
23
|
-
FROM
|
21
|
+
FROM alpine:3.12.0 AS runner
|
24
22
|
|
25
23
|
# Update/Upgrade/Add packages
|
26
24
|
|
data/Makefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# Pass BASE_IMAGE=alpine:3.13.3
|
2
1
|
DOCKER_IMAGE_LATEST = betterlog
|
3
2
|
DOCKER_IMAGE = $(DOCKER_IMAGE_LATEST):$(REVISION_SHORT)
|
4
3
|
PROJECT_ID = betterplace-183212
|
@@ -48,15 +47,12 @@ tags: clean
|
|
48
47
|
build-info:
|
49
48
|
@echo $(DOCKER_IMAGE)
|
50
49
|
|
51
|
-
|
52
|
-
docker
|
53
|
-
|
54
|
-
build: pull-base
|
55
|
-
docker build -t $(DOCKER_IMAGE) --build-arg=BASE_IMAGE=$(BASE_IMAGE) .
|
50
|
+
build:
|
51
|
+
docker build -t $(DOCKER_IMAGE) .
|
56
52
|
$(MAKE) build-info
|
57
53
|
|
58
|
-
build-force:
|
59
|
-
docker build -t $(DOCKER_IMAGE) --
|
54
|
+
build-force:
|
55
|
+
docker build -t $(DOCKER_IMAGE) --no-cache .
|
60
56
|
$(MAKE) build-info
|
61
57
|
|
62
58
|
debug:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.13.1
|
data/betterlog.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 0.
|
2
|
+
# stub: betterlog 0.13.1 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.13.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]
|
10
10
|
s.authors = ["betterplace Developers".freeze]
|
11
|
-
s.date = "2020-
|
11
|
+
s.date = "2020-07-20"
|
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_sink
CHANGED
@@ -7,14 +7,14 @@ require 'json'
|
|
7
7
|
|
8
8
|
LOG_ENV = ENV.fetch('LOG_ENV', 'production')
|
9
9
|
|
10
|
+
@config = complex_config.log(LOG_ENV).sink
|
11
|
+
|
10
12
|
ENV['KUBECONFIG'] = File.join(
|
11
13
|
ENV.fetch('HOME'),
|
12
14
|
'.kube',
|
13
|
-
|
15
|
+
@config.cluster.name
|
14
16
|
)
|
15
17
|
|
16
|
-
@config = complex_config.log(LOG_ENV).sink
|
17
|
-
|
18
18
|
def authenticate
|
19
19
|
return if File.exist?(ENV['KUBECONFIG'])
|
20
20
|
context = [
|
data/cloudbuild.yaml
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
steps:
|
2
2
|
- name: eu.gcr.io/betterplace-183212/better-builder
|
3
|
-
args: ['
|
4
|
-
- name: eu.gcr.io/betterplace-183212/better-builder
|
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}', '.']
|
3
|
+
args: ['build', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA', '-t', 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}', '.']
|
6
4
|
images:
|
7
5
|
- 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}:$SHORT_SHA'
|
8
6
|
- 'eu.gcr.io/$PROJECT_ID/${_IMAGE_NAME}'
|
data/lib/betterlog/log.rb
CHANGED
@@ -90,13 +90,15 @@ module Betterlog
|
|
90
90
|
#
|
91
91
|
# @param name the name of the recorded metric.
|
92
92
|
# @param value of the recorded metric, defaults to duration if block was given.
|
93
|
+
# @param success a Proc with parameter +result+ that returns true iff block
|
94
|
+
# result was asuccessful
|
93
95
|
# @param **rest additional rest is logged as well.
|
94
96
|
# @return [ Log ] this object itself.
|
95
|
-
def metric(name:, value: nil, **rest, &block)
|
96
|
-
time_block(&block)
|
97
|
+
def metric(name:, value: nil, success: -> result { true }, **rest, &block)
|
98
|
+
result = time_block(&block)
|
97
99
|
rescue => error
|
98
100
|
e = Log::Event.ify(error)
|
99
|
-
rest |= e.
|
101
|
+
rest |= e.as_json.subhash(:error_class, :backtrace, :message)
|
100
102
|
rest[:message] = "#{rest[:message].inspect} while measuring metric #{name}"
|
101
103
|
raise error
|
102
104
|
ensure
|
@@ -107,6 +109,7 @@ module Betterlog
|
|
107
109
|
event = build_metric(
|
108
110
|
name: name,
|
109
111
|
value: value || timed_duration,
|
112
|
+
success: success.(result),
|
110
113
|
**rest
|
111
114
|
)
|
112
115
|
emit event
|
@@ -122,6 +125,21 @@ module Betterlog
|
|
122
125
|
instance.context(data_hash)
|
123
126
|
end
|
124
127
|
|
128
|
+
def emit(event)
|
129
|
+
l = caller_locations.reverse_each.each_cons(3).find { |c, n1, n2|
|
130
|
+
n2.absolute_path =~ /betterlog\/log\.rb/ and break c # TODO check if this still works
|
131
|
+
}
|
132
|
+
if l
|
133
|
+
event[:location] = [ l.absolute_path, l.lineno ] * ?:
|
134
|
+
end
|
135
|
+
event[:emitter] = self.class.name.downcase
|
136
|
+
notify(event)
|
137
|
+
logger.send(event.severity.to_sym, event.to_json)
|
138
|
+
self
|
139
|
+
ensure
|
140
|
+
GlobalMetadata.data.clear
|
141
|
+
end
|
142
|
+
|
125
143
|
private
|
126
144
|
|
127
145
|
def protect
|
@@ -155,21 +173,6 @@ module Betterlog
|
|
155
173
|
)
|
156
174
|
end
|
157
175
|
|
158
|
-
def emit(event)
|
159
|
-
l = caller_locations.reverse_each.each_cons(3).find { |c, n1, n2|
|
160
|
-
n2.absolute_path =~ /betterlog\/log\.rb/ and break c # TODO check if this still works
|
161
|
-
}
|
162
|
-
if l
|
163
|
-
event[:location] = [ l.absolute_path, l.lineno ] * ?:
|
164
|
-
end
|
165
|
-
event[:emitter] = self.class.name.downcase
|
166
|
-
notify(event)
|
167
|
-
logger.send(event.severity.to_sym, event.to_json)
|
168
|
-
self
|
169
|
-
ensure
|
170
|
-
GlobalMetadata.data.clear
|
171
|
-
end
|
172
|
-
|
173
176
|
def notify(event)
|
174
177
|
if event.notify?
|
175
178
|
Notifiers.notify(event)
|
data/lib/betterlog/log/event.rb
CHANGED
data/lib/betterlog/logger.rb
CHANGED
data/lib/betterlog/notifiers.rb
CHANGED
data/lib/betterlog/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Betterlog::Log::Event do
|
4
|
-
describe '#
|
4
|
+
describe '#as_json' do
|
5
5
|
it 'dups hash before returning it' do
|
6
6
|
event = described_class.new
|
7
|
-
expect(event.
|
7
|
+
expect(event.as_json).not_to equal event.instance_variable_get(:@data)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
data/spec/betterlog/log_spec.rb
CHANGED
@@ -147,6 +147,7 @@ describe Betterlog::Log do
|
|
147
147
|
message: 'a metric controller.action=0.123',
|
148
148
|
name: 'controller.action',
|
149
149
|
value: 0.123,
|
150
|
+
success: true,
|
150
151
|
type: 'metric',
|
151
152
|
severity: 'info'
|
152
153
|
)
|
@@ -159,6 +160,7 @@ describe Betterlog::Log do
|
|
159
160
|
message: 'a metric controller.action=0.123',
|
160
161
|
name: 'controller.action',
|
161
162
|
value: 0.123,
|
163
|
+
success: true,
|
162
164
|
type: 'metric',
|
163
165
|
severity: :info,
|
164
166
|
)
|
@@ -172,6 +174,7 @@ describe Betterlog::Log do
|
|
172
174
|
foo: 'bar',
|
173
175
|
name: 'controller.action',
|
174
176
|
value: 0.123,
|
177
|
+
success: true,
|
175
178
|
type: 'metric',
|
176
179
|
severity: 'info'
|
177
180
|
)
|
@@ -184,14 +187,16 @@ describe Betterlog::Log do
|
|
184
187
|
message: 'a metric foo=10.0',
|
185
188
|
name: 'foo',
|
186
189
|
value: 10.0,
|
190
|
+
success: true,
|
187
191
|
duration: 10.0,
|
188
192
|
timestamp: "2011-11-11T10:11:21.000Z",
|
189
193
|
type: 'metric',
|
190
194
|
severity: 'info'
|
191
195
|
)
|
192
196
|
expect(instance).to receive(:emit).with(expected_event)
|
193
|
-
Log.metric(name: 'foo') do
|
197
|
+
Log.metric(name: 'foo', success: -> result { result == :success }) do
|
194
198
|
Time.dummy = Time.now + 10
|
199
|
+
:success
|
195
200
|
end
|
196
201
|
end
|
197
202
|
|
@@ -205,6 +210,7 @@ describe Betterlog::Log do
|
|
205
210
|
expected_event = Log::Event.new(
|
206
211
|
name: 'foo',
|
207
212
|
value: 3.0,
|
213
|
+
success: false,
|
208
214
|
duration: 3.0,
|
209
215
|
timestamp: "2011-11-11T10:11:14.000Z",
|
210
216
|
message: '"MyEx: we were fucked" while measuring metric foo',
|
@@ -216,10 +222,11 @@ describe Betterlog::Log do
|
|
216
222
|
expect(instance).to receive(:emit).with(expected_event)
|
217
223
|
raised = false
|
218
224
|
begin
|
219
|
-
Log.metric(name: 'foo') do
|
225
|
+
Log.metric(name: 'foo', success: -> result { result == :success }) do
|
220
226
|
Time.dummy = Time.now + 3
|
221
227
|
raise MyEx, "we were fucked"
|
222
228
|
Time.dummy = Time.now + 7
|
229
|
+
:success
|
223
230
|
end
|
224
231
|
rescue MyEx
|
225
232
|
raised = true
|
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.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace Developers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -248,7 +248,7 @@ files:
|
|
248
248
|
homepage: http://github.com/betterplace/betterlog
|
249
249
|
licenses: []
|
250
250
|
metadata: {}
|
251
|
-
post_install_message:
|
251
|
+
post_install_message:
|
252
252
|
rdoc_options:
|
253
253
|
- "--title"
|
254
254
|
- Betterlog
|
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
268
|
version: '0'
|
269
269
|
requirements: []
|
270
270
|
rubygems_version: 3.1.2
|
271
|
-
signing_key:
|
271
|
+
signing_key:
|
272
272
|
specification_version: 4
|
273
273
|
summary: Structured logging support for bp
|
274
274
|
test_files:
|