klogger-logger 1.1.0 → 1.3.1
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 +46 -0
- data/lib/klogger/logger.rb +26 -12
- data/lib/klogger.rb +12 -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: 05fcc83ebb5b6dcc9d947576d52b6d14ddd47c89de9ccfbe361df9dc1f9f33ed
|
4
|
+
data.tar.gz: f3f0d69f3427200dc9bbc74dee90f7dc8ad63aeb1364d8a47ec4c81e463189fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7e688edcf1a9454b422b9aefa6e687298b133a7f847b5c2f6dd0717a1afae395dd83ff68b639a238256e7f1a70f130ae5de18c779cbe6ac3f7c53f824631558
|
7
|
+
data.tar.gz: 77a325bb4eada003e7bfd46a47ec662db1436a4d85c9e12ce2da6bd7a1d5a8ba6d7bbe8ea5f79d73dbadff1baa6adebc1e968bbdc06da2f11e47bcd0b74e235b
|
@@ -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,46 @@
|
|
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_without_id(**tags)
|
17
|
+
add_without_id(**tags)
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
pop
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(**tags)
|
24
|
+
add(**tags)
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
pop
|
28
|
+
end
|
29
|
+
|
30
|
+
def add(**tags)
|
31
|
+
id = SecureRandom.hex(4)
|
32
|
+
@groups.value += [{ id: id, tags: tags }]
|
33
|
+
id
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_without_id(**tags)
|
37
|
+
@groups.value += [{ tags: tags }]
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def pop
|
42
|
+
@groups.value.pop
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
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,20 @@ 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
|
60
|
+
end
|
61
|
+
|
62
|
+
def tagged(**tags, &block)
|
63
|
+
@group_set.call_without_id(**tags, &block)
|
54
64
|
end
|
55
65
|
|
56
66
|
def silence!
|
@@ -99,7 +109,8 @@ module Klogger
|
|
99
109
|
end
|
100
110
|
|
101
111
|
def create_payload(severity, message, tags)
|
102
|
-
payload = { time: Time.now.to_s, severity: LEVELS[severity]&.to_s
|
112
|
+
payload = { time: Time.now.to_s, severity: LEVELS[severity]&.to_s }
|
113
|
+
payload[:logger] = @name if @name
|
103
114
|
payload.merge!(@tags)
|
104
115
|
|
105
116
|
if message.is_a?(Hash)
|
@@ -129,9 +140,12 @@ module Klogger
|
|
129
140
|
|
130
141
|
def add_groups_to_payload(payload)
|
131
142
|
group_ids = []
|
132
|
-
|
133
|
-
|
134
|
-
|
143
|
+
|
144
|
+
[Klogger.global_groups, @group_set].each do |group_set|
|
145
|
+
group_set.groups.each do |group|
|
146
|
+
payload.merge!(group[:tags])
|
147
|
+
group_ids << group[:id] if group[:id]
|
148
|
+
end
|
135
149
|
end
|
136
150
|
|
137
151
|
payload[:groups] = group_ids.join(',') if @include_group_ids
|
data/lib/klogger.rb
CHANGED
@@ -8,4 +8,16 @@ module Klogger
|
|
8
8
|
Logger.new(*args, **kwargs)
|
9
9
|
end
|
10
10
|
|
11
|
+
def self.global_groups
|
12
|
+
@global_groups ||= GroupSet.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.group(**tags, &block)
|
16
|
+
global_groups.call(**tags, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tagged(**tags, &block)
|
20
|
+
global_groups.call_without_id(**tags, &block)
|
21
|
+
end
|
22
|
+
|
11
23
|
end
|
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.1
|
4
|
+
version: 1.3.1
|
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
|