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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53332589726c07831fc34d3d63b7517de62fd1a75c11d1cbf772b6088d125eed
4
- data.tar.gz: 797d799f0268b110fe584ead9bdb9f9c3f779bca7d1e8d0fb75c796409a340c5
3
+ metadata.gz: b28b160e67e8d9321eebfb99ba3ade77f7409633ae3977b43abe5cdcdf62cb15
4
+ data.tar.gz: d2446915f9a3dd36ce5051316557816b884b33ea7ebbb3a3eeac8cb96ce528fc
5
5
  SHA512:
6
- metadata.gz: c773417845d13a54058bd01b1541a64fa9564bce845fec21efcd69fa23916a323da0c679d86e8950c7c7dea1fa7c4a18e02429f21b4d896c670d4bb952ade48e
7
- data.tar.gz: f95030ee5fe64f4cecd0cd9b15217897324bf2ac6aca1daed1a20a8daea233c029412a6a021dddd8bcd7d75d94aee673aa531f35bc8a214b6c07a0e666fca377
6
+ metadata.gz: 23d9b597ad2cc8cd4a5bc411f63a70f30930c066289aa17258319ddb8e9fdd68f092d8706ace0f5ce468e4ebfe4c8037b67007cb7e3accdf4489f11c6647dc11
7
+ data.tar.gz: 482721d054b7631906058eacf6c07db16235964ab7cf658e49ba92e8ed979beb05223240284d72267fe694aec6e66a576769bb862bfeba9d9f8ccf834e8d8187
@@ -14,7 +14,7 @@ jobs:
14
14
  runs-on: ubuntu-latest
15
15
  strategy:
16
16
  matrix:
17
- ruby-version: ['2.7', '3.0', '3.1']
17
+ ruby-version: ['2.7', '3.0', '3.1', '3.2']
18
18
 
19
19
  steps:
20
20
  - uses: actions/checkout@v2
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
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  def create_simple_logger
30
30
  logfile = Tempfile.new('my_test_log.log')
31
- ::Logger.new(logfile.path)
31
+ Logger.new(logfile.path)
32
32
  end
33
33
 
34
34
  # This task is used to help development of Lorekeeper. Use together with rbtrace
@@ -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 :level, # Current level, default: DEBUG
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 < @level
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
- # Hardcording newrelic, active_support/callbacks and zipkin-tracer now here.
117
- # In the future if this list grows, we may make it configurable.
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 { |line| line.match?(BLACKLISTED_FINGERPRINT) }
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
- BLACKLISTED_FINGERPRINT = %r{newrelic_rpm|active_support/callbacks.rb|zipkin-tracer}.freeze
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lorekeeper
4
- VERSION = '2.3.2'
4
+ VERSION = '2.5.0'
5
5
  end
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.3.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: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj