betterlog 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +1 -4
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/betterlog.gemspec +9 -9
- data/go.mod +12 -0
- data/go.sum +36 -0
- data/lib/betterlog/log/event.rb +2 -30
- data/lib/betterlog/log/severity.rb +19 -5
- data/lib/betterlog/logger.rb +8 -1
- data/lib/betterlog/version.rb +1 -1
- data/spec/betterlog/log/event_spec.rb +25 -0
- data/spec/betterlog/log/severity_spec.rb +51 -0
- data/spec/betterlog/logger_spec.rb +15 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e42b86b1161160f22929294cab981b61bca9f8b7556d10340aeb92d15b500a9
|
4
|
+
data.tar.gz: 0e5fea2a8341c8fa39c64075b51768e22b126ce2d3d2cae0df7884a49bbe23a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d39be241c8940ae2a8d8ba79635fbeff0c4eb86ca5d87de5f4650433b6e2a63fa2d4d45a31bafcdf87cdf82cda855cebc03641f2a882ab51c8cedc91fb2cd407
|
7
|
+
data.tar.gz: b4e08f6a9b787e2255f1e123cc0e9e04813884108dcbec54b3a50e0d03d76589410e3cc6f7b5b7097882f288185708663a9f2b0c4c3e4d073d076820ec46d5bb
|
data/Makefile
CHANGED
@@ -20,10 +20,7 @@ local: betterlog-server
|
|
20
20
|
REDIS_URL=$(REDIS_URL) ./betterlog-server
|
21
21
|
|
22
22
|
fetch: fake-package
|
23
|
-
go
|
24
|
-
go get -u github.com/labstack/echo
|
25
|
-
go get -u github.com/kelseyhightower/envconfig
|
26
|
-
go get -u github.com/go-redis/redis
|
23
|
+
go mod download
|
27
24
|
|
28
25
|
fake-package:
|
29
26
|
rm -rf $(GOPATH)/src/github.com/betterplace/betterlog
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ GemHadar do
|
|
18
18
|
title "#{name.camelize}"
|
19
19
|
executables %w[ betterlog betterlog_pusher betterlog_sink ]
|
20
20
|
|
21
|
-
dependency 'tins', '~>1.3', '>=1.
|
21
|
+
dependency 'tins', '~>1.3', '>=1.22.0'
|
22
22
|
dependency 'complex_config'
|
23
23
|
dependency 'file-tail', '~>1.0'
|
24
24
|
dependency 'json', '~>2.0'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/betterlog.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: betterlog 0.
|
2
|
+
# stub: betterlog 0.7.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.7.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 = "2019-
|
11
|
+
s.date = "2019-10-31"
|
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, ".travis.yml".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, "cmd/betterlog-server/LICENSE".freeze, "cmd/betterlog-server/main.go".freeze, "config/log.yml".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_spec.rb".freeze, "spec/betterlog/logger_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
16
|
+
s.files = [".gitignore".freeze, ".travis.yml".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, "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]
|
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
|
-
s.rubygems_version = "3.0.
|
19
|
+
s.rubygems_version = "3.0.6".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_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_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
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
29
29
|
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
30
30
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
31
|
-
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.
|
31
|
+
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
|
32
32
|
s.add_runtime_dependency(%q<complex_config>.freeze, [">= 0"])
|
33
33
|
s.add_runtime_dependency(%q<file-tail>.freeze, ["~> 1.0"])
|
34
34
|
s.add_runtime_dependency(%q<json>.freeze, ["~> 2.0"])
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
42
42
|
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
43
43
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
44
|
-
s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.
|
44
|
+
s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
|
45
45
|
s.add_dependency(%q<complex_config>.freeze, [">= 0"])
|
46
46
|
s.add_dependency(%q<file-tail>.freeze, ["~> 1.0"])
|
47
47
|
s.add_dependency(%q<json>.freeze, ["~> 2.0"])
|
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
|
|
55
55
|
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
56
56
|
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
57
57
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
58
|
-
s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.
|
58
|
+
s.add_dependency(%q<tins>.freeze, ["~> 1.3", ">= 1.22.0"])
|
59
59
|
s.add_dependency(%q<complex_config>.freeze, [">= 0"])
|
60
60
|
s.add_dependency(%q<file-tail>.freeze, ["~> 1.0"])
|
61
61
|
s.add_dependency(%q<json>.freeze, ["~> 2.0"])
|
data/go.mod
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module github.com/betterplace/betterlog
|
2
|
+
|
3
|
+
go 1.13
|
4
|
+
|
5
|
+
require (
|
6
|
+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
7
|
+
github.com/go-redis/redis v6.15.5+incompatible
|
8
|
+
github.com/kelseyhightower/envconfig v1.4.0 // indirect
|
9
|
+
github.com/labstack/echo v3.3.10+incompatible
|
10
|
+
github.com/labstack/gommon v0.3.0 // indirect
|
11
|
+
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
|
12
|
+
)
|
data/go.sum
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
2
|
+
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
3
|
+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
4
|
+
github.com/go-redis/redis v6.15.5+incompatible h1:pLky8I0rgiblWfa8C1EV7fPEUv0aH6vKRaYHc/YRHVk=
|
5
|
+
github.com/go-redis/redis v6.15.5+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
|
6
|
+
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
7
|
+
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
8
|
+
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
|
9
|
+
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
10
|
+
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
|
11
|
+
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
12
|
+
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
13
|
+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
14
|
+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
15
|
+
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
|
16
|
+
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
17
|
+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
18
|
+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
19
|
+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
20
|
+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
21
|
+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
22
|
+
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
23
|
+
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
24
|
+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
25
|
+
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
|
26
|
+
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
27
|
+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
28
|
+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
29
|
+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
30
|
+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
31
|
+
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
32
|
+
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
33
|
+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
34
|
+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
35
|
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
36
|
+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
data/lib/betterlog/log/event.rb
CHANGED
@@ -57,7 +57,7 @@ module Betterlog
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def initialize(data = {})
|
60
|
-
data = data.symbolize_keys_recursive | meta
|
60
|
+
data = data.symbolize_keys_recursive(circular: :circular) | meta
|
61
61
|
unless data.key?(:message)
|
62
62
|
data[:message] = "a #{data[:type]} type log message of severity #{data[:severity]}"
|
63
63
|
end
|
@@ -70,36 +70,8 @@ module Betterlog
|
|
70
70
|
@data = Hash[data.sort_by(&:first)]
|
71
71
|
end
|
72
72
|
|
73
|
-
class BreakCircles
|
74
|
-
def initialize
|
75
|
-
@seen = {}
|
76
|
-
end
|
77
|
-
|
78
|
-
IN_JSON = Tins::ModuleGroup[
|
79
|
-
Float, Integer, NilClass, FalseClass, TrueClass
|
80
|
-
]
|
81
|
-
|
82
|
-
def perform(object)
|
83
|
-
if @seen.key?(object.__id__)
|
84
|
-
:circular
|
85
|
-
else
|
86
|
-
@seen[object.__id__] = true
|
87
|
-
case
|
88
|
-
when h = object.ask_and_send(:to_hash)
|
89
|
-
h.each_with_object({}) { |(k, v), h| h[k.to_s.to_sym] = perform(v) }
|
90
|
-
when a = object.ask_and_send(:to_ary)
|
91
|
-
a.map { |o| perform(o) }
|
92
|
-
when IN_JSON === object
|
93
|
-
object
|
94
|
-
else
|
95
|
-
object.to_s
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
73
|
def as_hash(*a)
|
102
|
-
|
74
|
+
@data
|
103
75
|
end
|
104
76
|
|
105
77
|
def to_json(*a)
|
@@ -1,20 +1,34 @@
|
|
1
1
|
module Betterlog
|
2
2
|
class Log
|
3
3
|
class Severity
|
4
|
+
include ::Logger::Severity
|
4
5
|
include Comparable
|
5
6
|
|
7
|
+
class << self
|
8
|
+
thread_local :shared
|
9
|
+
|
10
|
+
def new(name)
|
11
|
+
name = name.to_sym if self.class === name
|
12
|
+
name = name.to_s.upcase.to_sym
|
13
|
+
self.shared ||= {}
|
14
|
+
shared[name] ||= super(name).freeze
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
def initialize(name)
|
7
|
-
|
19
|
+
name = name.to_sym if self.class === name
|
20
|
+
name = name.to_s.upcase.to_sym
|
21
|
+
@name = name
|
8
22
|
begin
|
9
|
-
@level =
|
23
|
+
@level = self.class.const_get(@name)
|
10
24
|
rescue NameError
|
11
25
|
@name = :UNKNOWN
|
12
|
-
@level =
|
26
|
+
@level = UNKNOWN
|
13
27
|
end
|
14
28
|
end
|
15
29
|
|
16
30
|
def self.all
|
17
|
-
@all_constants ||=
|
31
|
+
@all_constants ||= constants.map { |c| new(c) }
|
18
32
|
end
|
19
33
|
|
20
34
|
def to_i
|
@@ -34,7 +48,7 @@ module Betterlog
|
|
34
48
|
end
|
35
49
|
|
36
50
|
def <=>(other)
|
37
|
-
to_i <=> other.to_i
|
51
|
+
to_i <=> self.class.new(other).to_i
|
38
52
|
end
|
39
53
|
|
40
54
|
def eql?(other)
|
data/lib/betterlog/logger.rb
CHANGED
@@ -6,7 +6,14 @@ module Betterlog
|
|
6
6
|
@redis = redis
|
7
7
|
@name = name || self.class.name
|
8
8
|
@buffer_size = determine_buffer_size(buffer_size)
|
9
|
-
super(
|
9
|
+
super(nil, shift_age, shift_size, **opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.for_redis_url(url, shift_age = 0, shift_size = 1048576, **opts)
|
13
|
+
redis = Redis.new(url: url)
|
14
|
+
redis.ping
|
15
|
+
new(redis, shift_age, shift_size, **opts)
|
16
|
+
rescue Redis::CannotConnectError
|
10
17
|
end
|
11
18
|
|
12
19
|
private def determine_buffer_size(buffer_size)
|
data/lib/betterlog/version.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Betterlog::Log::Event do
|
4
|
+
describe '#to_json' do
|
5
|
+
it 'can deal with circular arrays' do
|
6
|
+
circular_array = [].tap { |arr| arr << arr }
|
7
|
+
event = Betterlog::Log::Event.new(array: circular_array)
|
8
|
+
expect(event.to_json).to include('"array":["circular"]')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can deal with circular hashes' do
|
12
|
+
circular_hash = {}.tap { |hash| hash['foo'] = hash }
|
13
|
+
event = Betterlog::Log::Event.new(hash: circular_hash)
|
14
|
+
expect(event.to_json).to include('"hash":{"foo":"circular"}')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not replace repeated scalar objects with "circular"' do
|
18
|
+
ary = [true, false, nil, 23, 3.14]
|
19
|
+
event = Betterlog::Log::Event.new(ary: ary << ary.dup)
|
20
|
+
expect(event.to_json).to include(<<~end.strip)
|
21
|
+
"ary":[true,false,null,23,3.14,[true,false,null,23,3.14]]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Betterlog::Log::Severity do
|
4
|
+
it 'has all constants' do
|
5
|
+
expect(described_class.all.map(&:to_sym).sort).to\
|
6
|
+
eq %i[ WARN ERROR FATAL UNKNOWN DEBUG INFO ].sort
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'resolves unknown severities to UNKNOWN' do
|
10
|
+
expect(described_class.new('NIX')).to eq(described_class.new(:UNKNOWN))
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'severity instance' do
|
14
|
+
subject do
|
15
|
+
described_class.new('error')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can be converted to integer' do
|
19
|
+
expect(subject.to_i).to eq 3
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be converted to symbol' do
|
23
|
+
expect(subject.to_sym).to eq :ERROR
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can be converted to string' do
|
27
|
+
expect(subject.to_s).to eq 'ERROR'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can be converted to json' do
|
31
|
+
expect(subject.to_json).to eq '"ERROR"'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can be converted via as_json' do
|
35
|
+
expect(subject.as_json).to eq :ERROR
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can be compared by level' do
|
39
|
+
expect(subject).to be < described_class.new(:FATAL)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'can be compared by level via symbol' do
|
43
|
+
expect(subject).to be < :FATAL
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'implements hash depending on name symbol' do
|
47
|
+
expect(subject.hash).to eq :ERROR.hash
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -5,6 +5,21 @@ describe Betterlog::Logger do
|
|
5
5
|
described_class.new(Redis.new)
|
6
6
|
end
|
7
7
|
|
8
|
+
describe '.for_redis_url' do
|
9
|
+
it 'can handle not being able to connect to redis' do
|
10
|
+
redis = double
|
11
|
+
allow(redis).to receive(:ping).and_raise Redis::CannotConnectError
|
12
|
+
allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
|
13
|
+
expect(Betterlog::Logger.for_redis_url('the_url')).to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can connect to redis for the url' do
|
17
|
+
redis = double(ping: 'PONG')
|
18
|
+
allow(Redis).to receive(:new).with(url: 'the_url').and_return redis
|
19
|
+
expect(Betterlog::Logger.for_redis_url('the_url')).to be_a Betterlog::Logger
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
8
23
|
describe '#<<' do
|
9
24
|
it 'writes to redis' do
|
10
25
|
expect(logger.instance_variable_get(:@redis)).to receive(:append).
|
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.7.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: 2019-
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
version: '1.3'
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 1.
|
78
|
+
version: 1.22.0
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -85,7 +85,7 @@ dependencies:
|
|
85
85
|
version: '1.3'
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
88
|
+
version: 1.22.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: complex_config
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,6 +225,8 @@ files:
|
|
225
225
|
- cmd/betterlog-server/LICENSE
|
226
226
|
- cmd/betterlog-server/main.go
|
227
227
|
- config/log.yml
|
228
|
+
- go.mod
|
229
|
+
- go.sum
|
228
230
|
- lib/betterlog.rb
|
229
231
|
- lib/betterlog/global_metadata.rb
|
230
232
|
- lib/betterlog/log.rb
|
@@ -237,6 +239,8 @@ files:
|
|
237
239
|
- lib/betterlog/railtie.rb
|
238
240
|
- lib/betterlog/version.rb
|
239
241
|
- spec/betterlog/global_metadata_spec.rb
|
242
|
+
- spec/betterlog/log/event_spec.rb
|
243
|
+
- spec/betterlog/log/severity_spec.rb
|
240
244
|
- spec/betterlog/log_spec.rb
|
241
245
|
- spec/betterlog/logger_spec.rb
|
242
246
|
- spec/spec_helper.rb
|
@@ -262,12 +266,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
266
|
- !ruby/object:Gem::Version
|
263
267
|
version: '0'
|
264
268
|
requirements: []
|
265
|
-
rubygems_version: 3.0.
|
269
|
+
rubygems_version: 3.0.6
|
266
270
|
signing_key:
|
267
271
|
specification_version: 4
|
268
272
|
summary: Structured logging support for bp
|
269
273
|
test_files:
|
270
274
|
- spec/betterlog/global_metadata_spec.rb
|
275
|
+
- spec/betterlog/log/event_spec.rb
|
276
|
+
- spec/betterlog/log/severity_spec.rb
|
271
277
|
- spec/betterlog/log_spec.rb
|
272
278
|
- spec/betterlog/logger_spec.rb
|
273
279
|
- spec/spec_helper.rb
|