lorekeeper 1.7.2 → 1.11.1

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: d8b0a7ef791f5abaf9fc2452ac135e9c5ec37510b879b19a02039cb3d1096342
4
- data.tar.gz: 418c008350fd3f1a221291266b3ab39e59d8333f796148bffba16f717399c066
3
+ metadata.gz: bfcc3f33a2a846246a7e85d8c8c2730d1099bb0c41b80b86998ffd6beb5736a4
4
+ data.tar.gz: 2e7b7f4a5e80c372ca5b17b4f961efa80bbd17e67713a075064c63659767bc2f
5
5
  SHA512:
6
- metadata.gz: fb7b5c1889b2e133bfe6f6a55be4424bcdfbe26718f2096889b1409d09609678ad57fc50fa2363fa17b7e59f79342422e1ac2ff3c22fd7572fec14fa09da5692
7
- data.tar.gz: 6933ce6d182c41fd7fd23950df831bc3e9f93c3d72c31198dd93906882f50a24395919b5cb2ba1a65587c0a5adc240b397872a27e25e2a7e251324661669e795
6
+ metadata.gz: fc4fa20700854b22f850129142a801ac56131e0f46e6f7ad74e69356821505715514c3b32041c58eaf3affa4dfe0ec951244e5e63222c26a08b115d9ecf8ea3f
7
+ data.tar.gz: 8de40794309ff297adee1865243dbc856a6b6f687cef620af6807b5a582e2011b00ab822a948e870368b01bcce9ac0c3071eba9d7b95ce8a75c8451468cc4dfa
data/.travis.yml CHANGED
@@ -2,14 +2,10 @@ language: ruby
2
2
  cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.3.8
6
- - 2.4.6
7
- - 2.5.5
8
- - 2.6.3
9
-
10
- before_install:
11
- - gem install rubygems-update -v 2.7.8
12
- - gem install bundler -v 1.17.3
13
- - bundle --version
5
+ - 2.4.9
6
+ - 2.5.8
7
+ - 2.6.6
8
+ - 2.7.2
9
+ - 3.0.0
14
10
 
15
11
  script: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 1.11.1
2
+ * Modify FastLogger#add to log progname as a message if no message and block are given
3
+
4
+ # 1.11.0
5
+ * Support for activerecord-session_store v2 which calls only silence and not silence_logger
6
+
7
+ # 1.10.0
8
+ * Use ActiveSupport::BacktraceCleaner to reduce noise in stacktrace output
9
+
10
+ # 1.9.0
11
+ * Remove Newrelic instrumentation information from stacktrace output
12
+
13
+ # 1.8.0
14
+ * Allow to use named parameters in the .exception method
15
+
1
16
  # 1.7.2
2
17
  * Add a second parameter to respond_to? to avoid Ruby 2.6 warnings
3
18
  * Drop support for unsupported Ruby 2.1 and Ruby 2.2
data/README.md CHANGED
@@ -169,6 +169,24 @@ Will output:
169
169
  }
170
170
  ```
171
171
 
172
+ Alternatively you can use named parameters:
173
+
174
+
175
+ ```ruby
176
+ rescue => e
177
+ logger.exception(e, message: "custom msg!", data: { some: { data: 123 } }, level: :warn)
178
+ end
179
+ ```
180
+
181
+ This is specially useful when there is no custom message or data:
182
+
183
+ ```ruby
184
+ rescue => e
185
+ logger.exception(e, level: :warn)
186
+ end
187
+ ```
188
+
189
+
172
190
 
173
191
  ## License
174
192
 
data/Rakefile CHANGED
@@ -50,10 +50,10 @@ task :benchmark do
50
50
  simple_log = create_simple_logger
51
51
 
52
52
  Benchmark.ips do |bm|
53
- bm.report('short content') { log.error(contents) }
54
- bm.report('Logger short content') { simple_log.info(contents) }
55
- bm.report('long content') { log.info(long_contents) }
56
- bm.report('Logger long content') { simple_log.info(long_contents) }
53
+ bm.report('JSON short content') { log.debug(contents) }
54
+ bm.report('Logger short content') { simple_log.debug(contents) }
55
+ bm.report('JSON long content') { log.debug(long_contents) }
56
+ bm.report('Logger long content') { simple_log.debug(long_contents) }
57
57
  bm.compare!
58
58
  end
59
59
 
@@ -54,9 +54,9 @@ module Lorekeeper
54
54
  end
55
55
 
56
56
  # This is part of the standard Logger API, we need this to be compatible
57
- def add(severity, message_param = nil, _ = nil, &block)
57
+ def add(severity, message_param = nil, progname = nil, &block)
58
58
  return true if severity < @level
59
- message = message_param || (block && block.call)
59
+ message = message_param || (block && block.call) || progname
60
60
  log_data(severity, message.freeze)
61
61
  end
62
62
 
@@ -68,6 +68,11 @@ module Lorekeeper
68
68
  yield if block_given?
69
69
  end
70
70
 
71
+ # activerecord-session_store v2 is now simply calling silence instead of silence_logger
72
+ def silence(&block)
73
+ yield if block_given?
74
+ end
75
+
71
76
  # inherited classes probably want to reimplement this
72
77
  def log_data(_severity, message)
73
78
  @iodevice.write(message)
@@ -9,6 +9,7 @@ module Lorekeeper
9
9
  def initialize(file)
10
10
  reset_state
11
11
  @base_fields = { MESSAGE => '', TIMESTAMP => '', LEVEL => '' }
12
+ @backtrace_cleaner = set_backtrace_cleaner
12
13
  super(file)
13
14
  end
14
15
 
@@ -29,7 +30,7 @@ module Lorekeeper
29
30
  LOGGING_METHODS.each do |method_name|
30
31
  define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) do
31
32
  return true if METHOD_SEVERITY_MAP[method_name] < @level
32
- extra_fields = { 'data' => (data || {}) }
33
+ extra_fields = { DATA => (data || {}) }
33
34
  with_extra_fields(extra_fields) { # Using do/end here only valid on Ruby>= 2.3
34
35
  add(METHOD_SEVERITY_MAP[method_name], message_param, nil, &block)
35
36
  }
@@ -61,25 +62,31 @@ module Lorekeeper
61
62
  end
62
63
 
63
64
  # @param exception: instance of a class inheriting from Exception
64
- # We will output backtrace twice. Once inside the stack so it can be parsed by software
65
- # And the other inside the message so it is readable to humans
66
- def exception(exception, custom_message = nil, custom_data = nil, level = :error)
67
- log_level = METHOD_SEVERITY_MAP[level] || ERROR
65
+ # By default message comes from exception.message
66
+ # Optional and named parameters to overwrite message, level and add data
67
+ def exception(exception, custom_message = nil, custom_data = nil, custom_level = :error,
68
+ message: nil, data: nil, level: nil) # Backwards compatible named params
69
+
70
+ param_level = level || custom_level
71
+ param_data = data || custom_data
72
+ param_message = message || custom_message
73
+
74
+ log_level = METHOD_SEVERITY_MAP[param_level] || ERROR
68
75
 
69
76
  if exception.is_a?(Exception)
70
- backtrace = exception.backtrace || []
77
+ backtrace = clean_backtrace(exception.backtrace || [])
71
78
  exception_fields = {
72
- 'exception' => "#{exception.class}: #{exception.message}",
73
- 'stack' => backtrace
79
+ EXCEPTION => "#{exception.class}: #{exception.message}",
80
+ STACK => backtrace
74
81
  }
75
- exception_fields['data'] = custom_data if custom_data
82
+ exception_fields[DATA] = param_data if param_data
76
83
 
77
- message = custom_message || exception.message
84
+ message = param_message || exception.message
78
85
  with_extra_fields(exception_fields) { log_data(log_level, message) }
79
86
  else
80
87
  log_data(METHOD_SEVERITY_MAP[:warn], 'Logger exception called without exception class.')
81
- message = "#{exception.class}: #{exception.inspect} #{custom_message}"
82
- with_extra_fields('data' => (custom_data || {})) { log_data(log_level, message) }
88
+ message = "#{exception.class}: #{exception.inspect} #{param_message}"
89
+ with_extra_fields(DATA => (param_data || {})) { log_data(log_level, message) }
83
90
  end
84
91
  end
85
92
 
@@ -89,11 +96,32 @@ module Lorekeeper
89
96
 
90
97
  private
91
98
 
99
+ # Some instrumentation libraries pollute the stacktrace and create a large output which may
100
+ # cause problems with certain logging backends.
101
+ # Hardcording newrelic and active_support/callbacks now here.
102
+ # In the future if this list grows, we may make it configurable.
103
+ def clean_backtrace(backtrace)
104
+ @backtrace_cleaner&.clean(backtrace) || backtrace
105
+ end
106
+
107
+ def set_backtrace_cleaner
108
+ return nil unless defined?(ActiveSupport::BacktraceCleaner)
109
+
110
+ cleaner = ActiveSupport::BacktraceCleaner.new
111
+ cleaner.remove_silencers!
112
+ cleaner.add_silencer { |line| line.match?(BLACKLISTED_FINGERPRINT) }
113
+ cleaner
114
+ end
115
+
92
116
  THREAD_KEY = 'lorekeeper_jsonlogger_key' # Shared by all threads but unique by thread
93
117
  LEVEL = 'level'
94
118
  MESSAGE = 'message'
95
119
  TIMESTAMP = 'timestamp'
96
120
  DATE_FORMAT = '%FT%T.%6NZ'
121
+ EXCEPTION = 'exception'
122
+ STACK = 'stack'
123
+ DATA = 'data'
124
+ BLACKLISTED_FINGERPRINT = %r{newrelic_rpm|active_support/callbacks.rb}.freeze
97
125
 
98
126
  def with_extra_fields(fields)
99
127
  state[:extra_fields] = fields
@@ -108,11 +136,12 @@ module Lorekeeper
108
136
  end
109
137
 
110
138
  def log_data(severity, message)
139
+ current_state = state # Accessing state is slow. Do it only once per call.
111
140
  # merging is slow, we do not want to merge with empty hash if possible
112
- fields_to_log = if state[:extra_fields].empty?
113
- state[:base_fields]
141
+ fields_to_log = if current_state[:extra_fields].empty?
142
+ current_state[:base_fields]
114
143
  else
115
- state[:base_fields].merge(state[:extra_fields])
144
+ current_state[:base_fields].merge(current_state[:extra_fields])
116
145
  end
117
146
 
118
147
  fields_to_log[MESSAGE] = message
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lorekeeper
4
- VERSION = '1.7.2'
4
+ VERSION = '1.11.1'
5
5
  end
data/lorekeeper.gemspec CHANGED
@@ -20,10 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.required_ruby_version = '>= 2.3.0'
23
+ spec.required_ruby_version = '>= 2.4.0'
24
24
 
25
25
  spec.add_dependency 'oj', '>= 3.4', '< 4.0'
26
26
 
27
+ spec.add_development_dependency 'activesupport', '>= 4.0'
27
28
  spec.add_development_dependency 'bundler', '>= 1.16', '< 3.0'
28
29
  spec.add_development_dependency 'rake', '~> 12.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.8'
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: 1.7.2
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Polo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-24 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -191,7 +205,7 @@ homepage: https://github.com/JordiPolo/lorekeeper
191
205
  licenses:
192
206
  - MIT
193
207
  metadata: {}
194
- post_install_message:
208
+ post_install_message:
195
209
  rdoc_options: []
196
210
  require_paths:
197
211
  - lib
@@ -199,15 +213,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
213
  requirements:
200
214
  - - ">="
201
215
  - !ruby/object:Gem::Version
202
- version: 2.3.0
216
+ version: 2.4.0
203
217
  required_rubygems_version: !ruby/object:Gem::Requirement
204
218
  requirements:
205
219
  - - ">="
206
220
  - !ruby/object:Gem::Version
207
221
  version: '0'
208
222
  requirements: []
209
- rubygems_version: 3.0.2
210
- signing_key:
223
+ rubygems_version: 3.2.15
224
+ signing_key:
211
225
  specification_version: 4
212
226
  summary: Very fast JSON logger
213
227
  test_files: []