betterlog 0.12.0 → 0.14.0

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: 881c76f1faf7c6783210c43f1c4c720d43cfc794da8385c27267080325f01af2
4
- data.tar.gz: 6e266178a87eb7c1f526bcb9a70fc13b5bfc5ff642d8b2a63b0bb95e4b43053b
3
+ metadata.gz: ca69ec750626ef4b6a76e40dcfb19bc1a9334410ee60b2714c611afb21a804c6
4
+ data.tar.gz: 1ec3c97e0aac9f04452606c1af507c7102aac37033a8c371841435dcd152c6c7
5
5
  SHA512:
6
- metadata.gz: 3036a50353157aece676091b0f245cbe30976fd707a214863546768bf3a20aa736c016c0e730f7cca11817fb410e293a40f20e2999620e6350b183d531e6d069
7
- data.tar.gz: 4abee0552ed87ff53b35f562d5306c8edd24b18e45f4deed25e2b33098b9dea0d57e911f0a4b3914187c94f483557a163d3833ce1e386f1a63fc043b0dc53054
6
+ metadata.gz: aecbebf1fe2fdb3a9341ac6c0e9704bb8c20161ffb3c76fc11d2de386345a6f8d4d96cd103e97dc115e1b290d9f63144ae130984626e53d87b2b91feadf0b7f3
7
+ data.tar.gz: 01cab4c0d493f3b9ae5a884338121f1b758838709050e375c8d85a433bae129e9cb7d5c8ccd0664f8afa9a4fe99b3f8ad1513ee6b53f6853b745233cc18795ee
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.12.0
1
+ 0.14.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.12.0 ruby lib
2
+ # stub: betterlog 0.14.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.12.0"
6
+ s.version = "0.14.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-04-02"
11
+ s.date = "2020-07-30"
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}'
@@ -2,6 +2,7 @@ require 'tins/xt'
2
2
  require 'json'
3
3
  require 'logger'
4
4
  require 'time'
5
+ require 'complex_config'
5
6
  require 'term/ansicolor'
6
7
 
7
8
  module Betterlog
@@ -7,12 +7,16 @@ require 'betterlog/log/severity'
7
7
  module Betterlog
8
8
  class Log
9
9
  include Tins::SexySingleton
10
+ extend ComplexConfig::Provider::Shortcuts
10
11
 
11
12
  class_attr_accessor :default_logger
12
13
  self.default_logger = Logger.new(STDERR)
14
+ if level = cc.log.level?
15
+ default_logger.level = level
16
+ end
13
17
 
14
18
  def logger
15
- defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new(STDERR)
19
+ defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : self.class.default_logger
16
20
  end
17
21
 
18
22
  # Logs a message on severity info.
@@ -98,7 +102,7 @@ module Betterlog
98
102
  result = time_block(&block)
99
103
  rescue => error
100
104
  e = Log::Event.ify(error)
101
- rest |= e.as_hash.subhash(:error_class, :backtrace, :message)
105
+ rest |= e.as_json.subhash(:error_class, :backtrace, :message)
102
106
  rest[:message] = "#{rest[:message].inspect} while measuring metric #{name}"
103
107
  raise error
104
108
  ensure
@@ -125,6 +129,21 @@ module Betterlog
125
129
  instance.context(data_hash)
126
130
  end
127
131
 
132
+ def emit(event)
133
+ l = caller_locations.reverse_each.each_cons(3).find { |c, n1, n2|
134
+ n2.absolute_path =~ /betterlog\/log\.rb/ and break c # TODO check if this still works
135
+ }
136
+ if l
137
+ event[:location] = [ l.absolute_path, l.lineno ] * ?:
138
+ end
139
+ event[:emitter] = self.class.name.downcase
140
+ notify(event)
141
+ logger.send(event.severity.to_sym, event.to_json)
142
+ self
143
+ ensure
144
+ GlobalMetadata.data.clear
145
+ end
146
+
128
147
  private
129
148
 
130
149
  def protect
@@ -158,21 +177,6 @@ module Betterlog
158
177
  )
159
178
  end
160
179
 
161
- def emit(event)
162
- l = caller_locations.reverse_each.each_cons(3).find { |c, n1, n2|
163
- n2.absolute_path =~ /betterlog\/log\.rb/ and break c # TODO check if this still works
164
- }
165
- if l
166
- event[:location] = [ l.absolute_path, l.lineno ] * ?:
167
- end
168
- event[:emitter] = self.class.name.downcase
169
- notify(event)
170
- logger.send(event.severity.to_sym, event.to_json)
171
- self
172
- ensure
173
- GlobalMetadata.data.clear
174
- end
175
-
176
180
  def notify(event)
177
181
  if event.notify?
178
182
  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)
@@ -2,6 +2,7 @@ module Betterlog
2
2
  class Log
3
3
  class EventFormatter
4
4
  include Term::ANSIColor
5
+ include ComplexConfig::Provider::Shortcuts
5
6
 
6
7
  def initialize(event)
7
8
  @event = event
@@ -52,7 +53,8 @@ module Betterlog
52
53
  invisible = $1.full?
53
54
  directive = $2
54
55
  key = $3
55
- if value = @event[key]
56
+ value = @event[key]
57
+ unless value.nil?
56
58
  formatted_value =
57
59
  if directive
58
60
  case directive
@@ -1,6 +1,7 @@
1
1
  module Betterlog
2
2
  class LogEventFormatter < ActiveSupport::Logger::Formatter
3
3
  include ActiveSupport::TaggedLogging::Formatter
4
+ include ComplexConfig::Provider::Shortcuts
4
5
 
5
6
  def emitter
6
7
  'legacy'
@@ -2,9 +2,15 @@ require 'redis'
2
2
 
3
3
  module Betterlog
4
4
  class Logger < ::Logger
5
+ include ComplexConfig::Provider::Shortcuts
6
+
5
7
  def initialize(redis, shift_age = 0, shift_size = 1048576, name: nil, buffer_size: nil, **opts)
6
8
  @redis = redis
7
9
  @fallback = ::Logger.new(STDERR)
10
+ if level = cc.log.level?
11
+ self.level = level
12
+ @fallback.level = level
13
+ end
8
14
  @name = name || self.class.name
9
15
  @buffer_size = determine_buffer_size(buffer_size)
10
16
  super(nil, shift_age, shift_size, **opts)
@@ -83,7 +89,7 @@ module Betterlog
83
89
  rescue Redis::BaseConnectionError
84
90
  end
85
91
 
86
- @redis.exists(@name) or return Enumerator.new {}
92
+ @redis.exists?(@name) or return Enumerator.new {}
87
93
 
88
94
  Enumerator.new do |y|
89
95
  name_tmp = "#{@name}_#{rand}"
@@ -92,7 +98,9 @@ module Betterlog
92
98
  s = 0
93
99
  e = @redis.strlen(name_tmp) - 1
94
100
  until s > e
95
- y.yield @redis.getrange(name_tmp, s, s + chunk_size - 1)
101
+ range = @redis.getrange(name_tmp, s, s + chunk_size - 1)
102
+ range.force_encoding 'ASCII-8BIT'
103
+ y.yield range
96
104
  s += chunk_size
97
105
  end
98
106
 
@@ -115,9 +123,10 @@ module Betterlog
115
123
  chunk_size > 0 or raise ArgumentError, 'chunk_size > 0 required'
116
124
  Enumerator.new do |y|
117
125
  buffer = ''
126
+ buffer.encode! 'ASCII-8BIT'
118
127
  each_chunk(chunk_size: chunk_size) do |chunk|
119
128
  buffer << chunk
120
- buffer.gsub!(/\A(.*?#$/)/) do |line|
129
+ buffer.gsub!(/\A(.*?#$/)/n) do |line|
121
130
  y.yield(line)
122
131
  ''
123
132
  end
@@ -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.12.0'
3
+ VERSION = '0.14.0'
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
 
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.12.0
4
+ version: 0.14.0
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-30 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: