lorekeeper 2.3.2 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/README.md +9 -0
- data/Rakefile +1 -1
- data/lib/lorekeeper/fast_logger.rb +32 -3
- data/lib/lorekeeper/json_logger.rb +36 -4
- data/lib/lorekeeper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b28b160e67e8d9321eebfb99ba3ade77f7409633ae3977b43abe5cdcdf62cb15
|
4
|
+
data.tar.gz: d2446915f9a3dd36ce5051316557816b884b33ea7ebbb3a3eeac8cb96ce528fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d9b597ad2cc8cd4a5bc411f63a70f30930c066289aa17258319ddb8e9fdd68f092d8706ace0f5ce468e4ebfe4c8037b67007cb7e3accdf4489f11c6647dc11
|
7
|
+
data.tar.gz: 482721d054b7631906058eacf6c07db16235964ab7cf658e49ba92e8ed979beb05223240284d72267fe694aec6e66a576769bb862bfeba9d9f8ccf834e8d8187
|
data/.github/workflows/build.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 2.5.0
|
2
|
+
* Update the backtrace cleaner in JSONLogger to remove web server and stdlib lines, and to strip the Rails.root prefix
|
3
|
+
|
4
|
+
# 2.4.0
|
5
|
+
* Add `#with_level` method support added to the stdlib's Logger in [#85](https://github.com/ruby/logger/issues/85)
|
6
|
+
* Support symbol log level setting
|
7
|
+
|
1
8
|
# 2.3.2
|
2
9
|
* Ensure additional fields are reset after logging
|
3
10
|
* Let Oj fallback to :object mode for non-representable data
|
data/README.md
CHANGED
@@ -20,6 +20,15 @@ bundle
|
|
20
20
|
```
|
21
21
|
|
22
22
|
|
23
|
+
## Configuration
|
24
|
+
|
25
|
+
Configuration is set through environment variables.
|
26
|
+
|
27
|
+
- `LOREKEEPER_DENYLIST`
|
28
|
+
- A comma separated list of keywords/phrases that will be excluded from the clean backtrace.
|
29
|
+
- default: `newrelic_rpm, active_support/callbacks.rb, zipkin-tracer, puma, phusion_passenger, opentelemetry`
|
30
|
+
|
31
|
+
|
23
32
|
## Usage
|
24
33
|
|
25
34
|
### Normal logging methods
|
data/Rakefile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'logger'
|
4
|
+
require 'fiber'
|
4
5
|
|
5
6
|
module Lorekeeper
|
6
7
|
# Very simple, very fast logger
|
7
8
|
class FastLogger
|
8
9
|
include ::Logger::Severity # contains the levels constants: DEBUG, ERROR, etc.
|
9
|
-
attr_accessor :
|
10
|
-
:formatter # Just for compatibility with Logger, not used
|
10
|
+
attr_accessor :formatter # Just for compatibility with Logger, not used
|
11
11
|
|
12
12
|
def debug?; level <= DEBUG; end
|
13
13
|
def info?; level <= INFO; end
|
@@ -19,6 +19,29 @@ module Lorekeeper
|
|
19
19
|
@level = DEBUG
|
20
20
|
@iodevice = LogDevice.new(file)
|
21
21
|
@file = file # We only keep this so we can inspect where we are sending the logs
|
22
|
+
@level_override = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def level
|
26
|
+
@level_override[Fiber.current] || @level
|
27
|
+
end
|
28
|
+
|
29
|
+
def level=(severity)
|
30
|
+
@level = coerce(severity)
|
31
|
+
end
|
32
|
+
|
33
|
+
def with_level(severity)
|
34
|
+
prev = level
|
35
|
+
@level_override[Fiber.current] = coerce(severity)
|
36
|
+
begin
|
37
|
+
yield
|
38
|
+
ensure
|
39
|
+
if prev
|
40
|
+
@level_override[Fiber.current] = prev
|
41
|
+
else
|
42
|
+
@level_override.delete(Fiber.current)
|
43
|
+
end
|
44
|
+
end
|
22
45
|
end
|
23
46
|
|
24
47
|
LOGGING_METHODS = %i[
|
@@ -55,7 +78,7 @@ module Lorekeeper
|
|
55
78
|
|
56
79
|
# This is part of the standard Logger API, we need this to be compatible
|
57
80
|
def add(severity, message_param = nil, progname = nil, &block)
|
58
|
-
return true if severity <
|
81
|
+
return true if severity < level
|
59
82
|
|
60
83
|
message = block&.call || message_param || progname
|
61
84
|
log_data(severity, message.freeze)
|
@@ -83,6 +106,12 @@ module Lorekeeper
|
|
83
106
|
@iodevice.write(message)
|
84
107
|
end
|
85
108
|
|
109
|
+
def coerce(severity)
|
110
|
+
return severity if severity.is_a?(Integer)
|
111
|
+
|
112
|
+
METHOD_SEVERITY_MAP[severity] || raise(ArgumentError, "invalid log level: #{severity}")
|
113
|
+
end
|
114
|
+
|
86
115
|
require 'monitor'
|
87
116
|
# Mutex to avoid broken lines when multiple threads access the log file
|
88
117
|
class LogDeviceMutex
|
@@ -10,6 +10,11 @@ module Lorekeeper
|
|
10
10
|
reset_state
|
11
11
|
@base_fields = { TIMESTAMP => '', MESSAGE => '', LEVEL => '' }
|
12
12
|
@backtrace_cleaner = set_backtrace_cleaner
|
13
|
+
@rails_root = defined?(Rails.root) ? Rails.root.to_s : nil
|
14
|
+
@rails_root_size = @rails_root.to_s.size
|
15
|
+
@gem_path = defined?(Gem.path) ? Gem.path : []
|
16
|
+
@denylisted_fingerprint = denylisted_fingerprint
|
17
|
+
|
13
18
|
super(file)
|
14
19
|
end
|
15
20
|
|
@@ -113,18 +118,38 @@ module Lorekeeper
|
|
113
118
|
|
114
119
|
# Some instrumentation libraries pollute the stacktrace and create a large output which may
|
115
120
|
# cause problems with certain logging backends.
|
116
|
-
#
|
117
|
-
#
|
121
|
+
# Cleaner defaults to newrelic, active_support/callbacks, zipkin-tracer, opentelemetry, web servers,
|
122
|
+
# and stdlib now but can be configured by using LOREKEEPER_DENYLIST env var.
|
118
123
|
def clean_backtrace(backtrace)
|
124
|
+
backtrace = filter_rails_root_backtrace(backtrace)
|
119
125
|
@backtrace_cleaner&.clean(backtrace) || backtrace
|
120
126
|
end
|
121
127
|
|
128
|
+
def filter_rails_root_backtrace(backtrace)
|
129
|
+
return backtrace unless @rails_root
|
130
|
+
|
131
|
+
last_index = nil
|
132
|
+
result = []
|
133
|
+
backtrace.each_with_index do |line, idx|
|
134
|
+
if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) }
|
135
|
+
result << line[@rails_root_size..]
|
136
|
+
last_index = idx
|
137
|
+
else
|
138
|
+
result << line
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
last_index ? result[..last_index] : result
|
143
|
+
end
|
144
|
+
|
122
145
|
def set_backtrace_cleaner
|
123
146
|
return nil unless defined?(ActiveSupport::BacktraceCleaner)
|
124
147
|
|
125
148
|
cleaner = ActiveSupport::BacktraceCleaner.new
|
126
149
|
cleaner.remove_silencers!
|
127
|
-
cleaner.add_silencer
|
150
|
+
cleaner.add_silencer do |line|
|
151
|
+
line.match?(@denylisted_fingerprint) || line.start_with?(RbConfig::CONFIG['rubylibdir'])
|
152
|
+
end
|
128
153
|
cleaner
|
129
154
|
end
|
130
155
|
|
@@ -136,7 +161,14 @@ module Lorekeeper
|
|
136
161
|
EXCEPTION = 'exception'
|
137
162
|
STACK = 'stack'
|
138
163
|
DATA = 'data'
|
139
|
-
|
164
|
+
DENYLISTED_FINGERPRINT =
|
165
|
+
%r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer|puma|phusion_passenger|opentelemetry}.freeze
|
166
|
+
|
167
|
+
def denylisted_fingerprint
|
168
|
+
return DENYLISTED_FINGERPRINT unless ENV.key?('LOREKEEPER_DENYLIST')
|
169
|
+
|
170
|
+
/#{ENV.fetch('LOREKEEPER_DENYLIST').split(',').map(&:strip).join('|')}/
|
171
|
+
end
|
140
172
|
|
141
173
|
def with_extra_fields(fields)
|
142
174
|
state[:extra_fields] = fields
|
data/lib/lorekeeper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lorekeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Polo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|