betterlog 0.19.0 → 0.20.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: 899c93328c9c225bb2611b62d1d8dcf981cfef0ab476a94a5bcc1024a893d4f4
4
- data.tar.gz: 462aa3526876d4fcdc0bb5107261840bcebfed4eed423b8a76d9bab4514a2469
3
+ metadata.gz: 9dd0b86a27bcfa9be03314d034c5769db0b5aa4c871d101f5dc372605473013c
4
+ data.tar.gz: 9b939b15113a229abc71de6d75c1df3f1dd52745c94969299b511d532bbda81e
5
5
  SHA512:
6
- metadata.gz: 50249915c7d17fab617bb8e1c207e854840f355cb7a5ecc5a2ee4602424bfa32f2b32b43c1149e446c221108f14d3dda5c6585024a78819bbe639a357af1a19b
7
- data.tar.gz: 6e34ab32fa4d1dbb1cf93ce83b59f6a29bf78c018a5de8a98c8e3311c0d910c93c185fc7e9625369c10d2b3084c218b64a3a83e0602516bad8feff9032b0d76c
6
+ metadata.gz: c06fcf1d1734a6948dc67af44038e1da6497668e19ca744f011a953e55e921767cccae50668f03519cb7fba0ace4870a06b6ba04769cb4193dd244556ff72b98
7
+ data.tar.gz: 79965033190f63db5fa63e9e23923252c293a551fe700fc9de51ce07fa61e73e8849d6bec36906bc575c66e574cfc429d1c7ae1ceb4e6fe68717b960479eea31
@@ -3,7 +3,7 @@ name: Betterlog pipeline
3
3
  agent:
4
4
  machine:
5
5
  type: e1-standard-2
6
- os_image: ubuntu1804
6
+ os_image: ubuntu2004
7
7
 
8
8
  blocks:
9
9
  - name: Caching
@@ -14,7 +14,7 @@ blocks:
14
14
  jobs:
15
15
  - name: cache bundle
16
16
  commands:
17
- - sem-version ruby 2.7.2
17
+ - sem-version ruby $(awk '/^ruby/ { print $2 }' .tool-versions)
18
18
  - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
19
19
  - bundle config set path 'vendor/bundle'
20
20
  - bundle config jobs $(getconf _NPROCESSORS_ONLN)
@@ -31,7 +31,7 @@ blocks:
31
31
  - checkout
32
32
 
33
33
  # Setup ruby
34
- - sem-version ruby 2.7.2
34
+ - sem-version ruby $(awk '/^ruby/ { print $2 }' .tool-versions)
35
35
 
36
36
  # Setup gems
37
37
  - cache restore gems-$SEMAPHORE_GIT_BRANCH,gems-master
@@ -60,4 +60,4 @@ blocks:
60
60
  - name: Building and pushing
61
61
  commands:
62
62
  - make build
63
- - test "$SEMAPHORE_GIT_BRANCH" = "master" && make push-latest
63
+ - test "$SEMAPHORE_GIT_BRANCH" = "master" && make push-latest || true
data/.tool-versions CHANGED
@@ -1,2 +1,3 @@
1
- golang 1.16
2
1
  ruby 3.0.2
2
+ bundler 2.2.26
3
+ golang 1.17
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.19.0
1
+ 0.20.0
data/betterlog.gemspec CHANGED
@@ -1,24 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterlog 0.19.0 ruby lib
2
+ # stub: betterlog 0.20.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterlog".freeze
6
- s.version = "0.19.0"
6
+ s.version = "0.20.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 = "2021-09-21"
11
+ s.date = "2021-10-26"
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]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze]
16
- s.files = [".gitignore".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "bin/betterlog_sink".freeze, "cloudbuild.yaml".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "go.mod".freeze, "go.sum".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
+ s.files = [".gitignore".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, "Dockerfile".freeze, "Gemfile".freeze, "LICENSE".freeze, "Makefile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "betterlog.gemspec".freeze, "betterlog/config.go".freeze, "betterlog/healthz.go".freeze, "betterlog/redis_cert_cache.go".freeze, "bin/betterlog".freeze, "bin/betterlog_pusher".freeze, "bin/betterlog_sink".freeze, "cloudbuild.yaml".freeze, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".freeze, "go.mod".freeze, "go.sum".freeze, "lib/betterlog.rb".freeze, "lib/betterlog/global_metadata.rb".freeze, "lib/betterlog/log.rb".freeze, "lib/betterlog/log/event.rb".freeze, "lib/betterlog/log/event_formatter.rb".freeze, "lib/betterlog/log/severity.rb".freeze, "lib/betterlog/log_event_formatter.rb".freeze, "lib/betterlog/logger.rb".freeze, "lib/betterlog/notifiers.rb".freeze, "lib/betterlog/railtie.rb".freeze, "lib/betterlog/version.rb".freeze, "spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "http://github.com/betterplace/betterlog".freeze
18
18
  s.rdoc_options = ["--title".freeze, "Betterlog".freeze, "--main".freeze, "README.md".freeze]
19
19
  s.rubygems_version = "3.2.22".freeze
20
20
  s.summary = "Structured logging support for bp".freeze
21
- s.test_files = ["spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
21
+ s.test_files = ["spec/betterlog/global_metadata_spec.rb".freeze, "spec/betterlog/log/event_spec.rb".freeze, "spec/betterlog/log/severity_spec.rb".freeze, "spec/betterlog/log_event_formatter_spec.rb".freeze, "spec/betterlog/log_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  s.specification_version = 4
@@ -1,3 +1,5 @@
1
+ require 'term/ansicolor'
2
+
1
3
  module Betterlog
2
4
  class LogEventFormatter < ActiveSupport::Logger::Formatter
3
5
  include ActiveSupport::TaggedLogging::Formatter
@@ -8,13 +10,16 @@ module Betterlog
8
10
  end
9
11
 
10
12
  def call(severity, timestamp, program, message)
11
- super
12
- message = message.to_s
13
+ message = super.to_s
13
14
  if cc.log.legacy_supported
14
15
  if message.blank?
15
- return ''
16
+ message = ''
16
17
  elsif !Log::Event.is?(message)
17
- m = message.sub(/\s+$/, '')
18
+
19
+ m = message.to_s
20
+ m = Term::ANSIColor.uncolor(m)
21
+ m = m.sub(/\s+$/, '')
22
+
18
23
  timestamp = timestamp.utc.iso8601(3)
19
24
  event = Log::Event.new(
20
25
  emitter: emitter,
@@ -26,7 +31,7 @@ module Betterlog
26
31
  if backtrace = m.grep(/^\s*([^:]+):(\d+)/)
27
32
  if backtrace.size > 1
28
33
  event[:backtrace] = backtrace.map(&:chomp)
29
- event[:message] = 'a logged backtrace'
34
+ event[:message] = backtrace.first
30
35
  end
31
36
  end
32
37
  if l = caller_locations.reverse_each.each_cons(2).find { |c, n|
@@ -42,7 +47,7 @@ module Betterlog
42
47
  rescue => e
43
48
  Betterlog::Log.logger.error(e)
44
49
  ensure
45
- # Do not "message << ?\n" - A frozn string may be passed in
50
+ # Do not "message << ?\n" - A frozen string may be passed in
46
51
  message.end_with?(?\n) or message = "#{message}\n"
47
52
  return message
48
53
  end
@@ -1,6 +1,6 @@
1
1
  module Betterlog
2
2
  # Betterlog version
3
- VERSION = '0.19.0'
3
+ VERSION = '0.20.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:
data/lib/betterlog.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'tins/xt'
2
2
  require 'json'
3
3
  require 'complex_config'
4
+ require 'term/ansicolor'
4
5
 
5
6
  module Betterlog
6
7
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+ module ActiveSupport
3
+ class Logger
4
+ class Formatter
5
+ def call(severity, timestamp, program, message)
6
+ message
7
+ end
8
+ end
9
+ end
10
+ module TaggedLogging
11
+ module Formatter
12
+ end
13
+ end
14
+ end
15
+ require 'betterlog/log_event_formatter'
16
+
17
+ describe Betterlog::LogEventFormatter do
18
+ let :red do
19
+ Term::ANSIColor.red { "red" }
20
+ end
21
+
22
+ it 'strips blank messages' do
23
+ message = described_class.new.(:info, Time.now, 'foo', ' ')
24
+ expect(message).to eq ?\n
25
+ end
26
+
27
+ it 'uncolors colored message strings' do
28
+ json = described_class.new.(:info, Time.now, 'foo', red)
29
+ data = JSON.parse(json)
30
+ expect(data['message']).to eq 'red'
31
+ end
32
+
33
+ it 'deconstructs backtraces' do
34
+ msg = <<~end
35
+ foo.rb:6:in `bar': hi (RuntimeError)
36
+ from foo.rb:2:in `foo'
37
+ from foo.rb:9:in `<main>'
38
+ end
39
+ json = described_class.new.(:info, Time.now, 'foo', msg)
40
+ data = JSON.parse(json)
41
+ expect(data['message']).to eq "foo.rb:6:in `bar': hi (RuntimeError)\n"
42
+ expect(data['backtrace']).to eq [
43
+ "foo.rb:6:in `bar': hi (RuntimeError)",
44
+ " from foo.rb:2:in `foo'",
45
+ " from foo.rb:9:in `<main>'"
46
+ ]
47
+ end
48
+ 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.19.0
4
+ version: 0.20.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: 2021-09-21 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -257,6 +257,7 @@ files:
257
257
  - spec/betterlog/global_metadata_spec.rb
258
258
  - spec/betterlog/log/event_spec.rb
259
259
  - spec/betterlog/log/severity_spec.rb
260
+ - spec/betterlog/log_event_formatter_spec.rb
260
261
  - spec/betterlog/log_spec.rb
261
262
  - spec/betterlog/logger_spec.rb
262
263
  - spec/spec_helper.rb
@@ -290,6 +291,7 @@ test_files:
290
291
  - spec/betterlog/global_metadata_spec.rb
291
292
  - spec/betterlog/log/event_spec.rb
292
293
  - spec/betterlog/log/severity_spec.rb
294
+ - spec/betterlog/log_event_formatter_spec.rb
293
295
  - spec/betterlog/log_spec.rb
294
296
  - spec/betterlog/logger_spec.rb
295
297
  - spec/spec_helper.rb