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 +4 -4
- data/.semaphore/semaphore.yml +4 -4
- data/.tool-versions +2 -1
- data/VERSION +1 -1
- data/betterlog.gemspec +5 -5
- data/lib/betterlog/log_event_formatter.rb +11 -6
- data/lib/betterlog/version.rb +1 -1
- data/lib/betterlog.rb +1 -0
- data/spec/betterlog/log_event_formatter_spec.rb +48 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dd0b86a27bcfa9be03314d034c5769db0b5aa4c871d101f5dc372605473013c
|
4
|
+
data.tar.gz: 9b939b15113a229abc71de6d75c1df3f1dd52745c94969299b511d532bbda81e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c06fcf1d1734a6948dc67af44038e1da6497668e19ca744f011a953e55e921767cccae50668f03519cb7fba0ace4870a06b6ba04769cb4193dd244556ff72b98
|
7
|
+
data.tar.gz: 79965033190f63db5fa63e9e23923252c293a551fe700fc9de51ce07fa61e73e8849d6bec36906bc575c66e574cfc429d1c7ae1ceb4e6fe68717b960479eea31
|
data/.semaphore/semaphore.yml
CHANGED
@@ -3,7 +3,7 @@ name: Betterlog pipeline
|
|
3
3
|
agent:
|
4
4
|
machine:
|
5
5
|
type: e1-standard-2
|
6
|
-
os_image:
|
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.
|
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.
|
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
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.20.0
|
data/betterlog.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 0.
|
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.
|
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-
|
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
|
-
|
16
|
+
message = ''
|
16
17
|
elsif !Log::Event.is?(message)
|
17
|
-
|
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] =
|
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
|
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
|
data/lib/betterlog/version.rb
CHANGED
data/lib/betterlog.rb
CHANGED
@@ -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.
|
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-
|
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
|