klogger-logger 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/klogger/formatters/go.rb +2 -2
- data/lib/klogger/group_set.rb +34 -0
- data/lib/klogger/logger.rb +22 -12
- data/lib/klogger.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d829e62b7472acd3c8c20e0ce8d5e3719c3bf2a5fa6752f23c503b64e56db99f
|
4
|
+
data.tar.gz: d8a76281e8ac428c1c5ffacffcc6edc24c3404742e755a5f831287aa0b1862d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58b478bddf41b569b4af77b0ef19ca70fccfd4b4f06f31d12c8c411f00f31ef1943f662f264b176e21c9df8087965187e525ddb11f4fad50a4b8e55fa00dcc98
|
7
|
+
data.tar.gz: 73cf53c1c9bd298e5b09518e2ce7f7903d077b9c81648a156a1ea1da61b20f9a287ec3e0cea5a3acde0b97a544f449b1b295466f978741db1b7862e9792a5b6b
|
@@ -15,7 +15,7 @@ module Klogger
|
|
15
15
|
string = String.new
|
16
16
|
string << time.strftime('%Y-%m-%d %H:%M:%S %z')
|
17
17
|
string << ' '
|
18
|
-
string << colorize(payload[:severity].ljust(
|
18
|
+
string << colorize(payload[:severity].ljust(7, ' ').upcase, payload[:severity].to_sym)
|
19
19
|
if payload[:message]
|
20
20
|
string << colorize(payload[:message], :white)
|
21
21
|
string << ' '
|
@@ -27,7 +27,7 @@ module Klogger
|
|
27
27
|
string << colorize(sanitize_value(value), :white)
|
28
28
|
string << ' '
|
29
29
|
end
|
30
|
-
string + "\n"
|
30
|
+
string.strip + "\n"
|
31
31
|
end
|
32
32
|
# rubocop:enable Metrics/AbcSize
|
33
33
|
# rubocop:enable Metrics/MethodLength
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'concurrent/atomic/thread_local_var'
|
4
|
+
|
5
|
+
module Klogger
|
6
|
+
class GroupSet
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@groups = Concurrent::ThreadLocalVar.new { [] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def groups
|
13
|
+
@groups.value
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(**tags)
|
17
|
+
add(**tags)
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
pop
|
21
|
+
end
|
22
|
+
|
23
|
+
def add(**tags)
|
24
|
+
id = SecureRandom.hex(4)
|
25
|
+
@groups.value += [{ id: id, tags: tags }]
|
26
|
+
id
|
27
|
+
end
|
28
|
+
|
29
|
+
def pop
|
30
|
+
@groups.value.pop
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/klogger/logger.rb
CHANGED
@@ -6,6 +6,7 @@ require 'klogger/formatters/json'
|
|
6
6
|
require 'klogger/formatters/simple'
|
7
7
|
require 'klogger/formatters/go'
|
8
8
|
require 'concurrent/atomic/thread_local_var'
|
9
|
+
require 'klogger/group_set'
|
9
10
|
|
10
11
|
module Klogger
|
11
12
|
class Logger < ::Logger
|
@@ -21,14 +22,14 @@ module Klogger
|
|
21
22
|
go: Formatters::Go
|
22
23
|
}.freeze
|
23
24
|
|
24
|
-
def initialize(name, destination: $stdout, formatter: :
|
25
|
+
def initialize(name = nil, destination: $stdout, formatter: :go, highlight: false, include_group_ids: false,
|
26
|
+
tags: {})
|
25
27
|
@name = name
|
26
28
|
@tags = tags
|
27
29
|
@destinations = []
|
28
|
-
@
|
30
|
+
@group_set = GroupSet.new
|
29
31
|
@silenced = Concurrent::ThreadLocalVar.new { false }
|
30
32
|
@include_group_ids = include_group_ids
|
31
|
-
|
32
33
|
super(destination)
|
33
34
|
self.formatter = FORMATTERS[formatter].new(highlight: highlight)
|
34
35
|
end
|
@@ -46,11 +47,16 @@ module Klogger
|
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
49
|
-
def group(**tags)
|
50
|
-
@
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def group(**tags, &block)
|
51
|
+
@group_set.call(**tags, &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_group(**tags)
|
55
|
+
@group_set.add(**tags)
|
56
|
+
end
|
57
|
+
|
58
|
+
def pop_group
|
59
|
+
@group_set.pop
|
54
60
|
end
|
55
61
|
|
56
62
|
def silence!
|
@@ -99,7 +105,8 @@ module Klogger
|
|
99
105
|
end
|
100
106
|
|
101
107
|
def create_payload(severity, message, tags)
|
102
|
-
payload = { time: Time.now.to_s, severity: LEVELS[severity]&.to_s
|
108
|
+
payload = { time: Time.now.to_s, severity: LEVELS[severity]&.to_s }
|
109
|
+
payload[:logger] = @name if @name
|
103
110
|
payload.merge!(@tags)
|
104
111
|
|
105
112
|
if message.is_a?(Hash)
|
@@ -129,9 +136,12 @@ module Klogger
|
|
129
136
|
|
130
137
|
def add_groups_to_payload(payload)
|
131
138
|
group_ids = []
|
132
|
-
|
133
|
-
|
134
|
-
|
139
|
+
|
140
|
+
[Klogger.global_groups, @group_set].each do |group_set|
|
141
|
+
group_set.groups.each do |group|
|
142
|
+
payload.merge!(group[:tags])
|
143
|
+
group_ids << group[:id]
|
144
|
+
end
|
135
145
|
end
|
136
146
|
|
137
147
|
payload[:groups] = group_ids.join(',') if @include_group_ids
|
data/lib/klogger.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klogger-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/klogger/formatters/go.rb
|
79
79
|
- lib/klogger/formatters/json.rb
|
80
80
|
- lib/klogger/formatters/simple.rb
|
81
|
+
- lib/klogger/group_set.rb
|
81
82
|
- lib/klogger/json_highlighter.rb
|
82
83
|
- lib/klogger/logger.rb
|
83
84
|
- lib/klogger/version.rb
|