betterlog 0.11.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93ac0b92fff87f8005af14b59044b35a17981c2fd30ca1a3614d52967cf711b8
4
- data.tar.gz: 22756efdebaa24185c28ffa2ba76cec177e83177f94b874d4bac13c3d8d87ac5
3
+ metadata.gz: 29fe6dd6fca5b0294e9f55388615d6d8b58885a2f1898682525d19f239bd4552
4
+ data.tar.gz: f5495f46f7a6473edbe7a1e4973f9ac021213eb121dd149f5b50d23d191ab9dc
5
5
  SHA512:
6
- metadata.gz: f4f4313920141cf7b4549da03362eb1ac585a8ac6f8d6bd80bc95cbff178797f507267ae9c9b56ab2423271c0a69dc5e9c3f0cb4c8454c7ff6824530ede26c8d
7
- data.tar.gz: 2626a52f7915d4a2699cfcbde0425a736e5c41d1fefb03e13adefaa44961f1f118ac44921f37f34fe9adb7a65b3ee03b145d3cb331e9ca7ac4e6909ca1a45097
6
+ metadata.gz: 1345db77124853df14e65a3bfb5680b7936de5711cc0f21449d172822e8f44981a500b03cc29a072781039e4692cfc544e63387d817fa1eb65c4ea55995d83c3
7
+ data.tar.gz: f63ed3284d529d6df4f76f3e885d1c52d6d7dbba024ee08c61fcce8e79e0b8f3e04c1a4d15c7c7de7f017568a3ffea0c0cdd9c4da7f649b38172317abf735a09
data/Dockerfile CHANGED
@@ -1,6 +1,4 @@
1
- ARG BASE_IMAGE
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 ${BASE_IMAGE} AS runner
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
- pull-base:
52
- docker pull $(BASE_IMAGE)
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: pull-base
59
- docker build -t $(DOCKER_IMAGE) --build-arg=BASE_IMAGE=$(BASE_IMAGE) --no-cache .
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.11.0
1
+ 0.13.1
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.11.0 ruby lib
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.11.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-04-02"
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]
@@ -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
- "betterlog-#{LOG_ENV}"
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 = [
@@ -1,8 +1,6 @@
1
1
  steps:
2
2
  - name: eu.gcr.io/betterplace-183212/better-builder
3
- args: ['pull', '${_BASE_IMAGE}']
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}'
@@ -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.as_hash.subhash(:error_class, :backtrace, :message)
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)
@@ -70,12 +70,12 @@ module Betterlog
70
70
  @data = Hash[data.sort_by(&:first)]
71
71
  end
72
72
 
73
- def as_hash(*a)
73
+ def as_json(*a)
74
74
  @data.dup
75
75
  end
76
76
 
77
77
  def to_json(*a)
78
- as_hash.to_json(*a)
78
+ as_json.to_json(*a)
79
79
  end
80
80
 
81
81
  def format(*args)
@@ -52,7 +52,8 @@ module Betterlog
52
52
  invisible = $1.full?
53
53
  directive = $2
54
54
  key = $3
55
- if value = @event[key]
55
+ value = @event[key]
56
+ unless value.nil?
56
57
  formatted_value =
57
58
  if directive
58
59
  case directive
@@ -83,7 +83,7 @@ module Betterlog
83
83
  rescue Redis::BaseConnectionError
84
84
  end
85
85
 
86
- @redis.exists(@name) or return Enumerator.new {}
86
+ @redis.exists?(@name) or return Enumerator.new {}
87
87
 
88
88
  Enumerator.new do |y|
89
89
  name_tmp = "#{@name}_#{rand}"
@@ -14,7 +14,7 @@ module Betterlog
14
14
 
15
15
  def self.notify(event)
16
16
  notifiers.each do |notifier|
17
- notifier.notify(event.notify?, event.as_hash)
17
+ notifier.notify(event.notify?, event.as_json)
18
18
  end
19
19
  end
20
20
 
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.11.0'
3
+ VERSION = '0.13.1'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Betterlog::Log::Event do
4
- describe '#as_hash' do
4
+ describe '#as_json' do
5
5
  it 'dups hash before returning it' do
6
6
  event = described_class.new
7
- expect(event.as_hash).not_to equal event.instance_variable_get(:@data)
7
+ expect(event.as_json).not_to equal event.instance_variable_get(:@data)
8
8
  end
9
9
  end
10
10
 
@@ -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.11.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-04-02 00:00:00.000000000 Z
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: