lumberjack 1.2.4 → 1.2.5

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: 477e85433c8d726c881946ab35ad3d3fc1cffc20ceeec9efc41a74f7bf91ef8d
4
- data.tar.gz: 325441e14a7f92374002069190cc3c9324e5ccae48a550aae705f177e877d62b
3
+ metadata.gz: afea02bfb6a11fe77b13b77958097461cc546672f0059cf4a9e5cbb81445a97d
4
+ data.tar.gz: d94096a3de319ebce142ca5264b15f62f067dd5dfeaf2a1184a886dfc6a16b80
5
5
  SHA512:
6
- metadata.gz: 2161522abc951fd9db62a6594bb5dbea0eb392aac7f42960818dbfe673f34822fcd6d3af3037a5ba6029f837ec54880c992b959a503a133c9be30ff81ae75c94
7
- data.tar.gz: cb0bea0a04c752eb2597ec57befc6391955adfb39f26201041ce7023c458e69b83a36ccdd1bdaeaa7bb04f41686441c6e083461fa40775b563570300507032f4
6
+ metadata.gz: '09250cd1360e5b0a2fcddc4f37504020adfcdcae809edf853c9580f34b1c63a0a834fe4fccb26b6b60b1a03eca2c736deaeeedd6ef5c59ed889be2eeff4ac65e'
7
+ data.tar.gz: 0e9c83f1df927ec79d906aaaecfd0a5326217f71b23e537cd4a75232a3a7c0c1f38aee6517ceb3baac09337eeb8fdd72737cfeb31d52c000775e46e8f13c4231
@@ -1,3 +1,8 @@
1
+ ## 1.2.5
2
+
3
+ * Fix logic with recursive reference guard in StructuredFormatter so it only suppresses Enumerable references.
4
+ * Add support for bang methods (error!) for setting the log level.
5
+
1
6
  ## 1.2.4
2
7
 
3
8
  * Enhance ActiveSupport::TaggedLogging support so code that Lumberjack loggers can be wrapped with a tagged logger.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.4
1
+ 1.2.5
@@ -6,6 +6,9 @@ module Lumberjack
6
6
  class Formatter
7
7
  # Dereference arrays and hashes and recursively call formatters on each element.
8
8
  class StructuredFormatter
9
+ class RecusiveReferenceError < StandardError
10
+ end
11
+
9
12
  def initialize(formatter = nil)
10
13
  @formatter = formatter
11
14
  end
@@ -18,31 +21,43 @@ module Lumberjack
18
21
 
19
22
  def call_with_references(obj, references)
20
23
  if obj.is_a?(Hash)
21
- hash = {}
22
- references << obj.object_id
23
- obj.each do |name, value|
24
- next if references.include?(value.object_id)
25
- references << value
26
- hash[name.to_s] = call_with_references(value, references)
24
+ with_object_reference(obj, references) do
25
+ hash = {}
26
+ obj.each do |name, value|
27
+ value = call_with_references(value, references)
28
+ hash[name.to_s] = value unless value.is_a?(RecusiveReferenceError)
29
+ end
30
+ hash
27
31
  end
28
- references.delete(obj.object_id)
29
- hash
30
32
  elsif obj.is_a?(Enumerable) && obj.respond_to?(:size) && obj.size != Float::INFINITY
31
- array = []
32
- references << obj.object_id
33
- obj.each do |value|
34
- next if references.include?(value.object_id)
35
- references << value
36
- array << call_with_references(value, references)
33
+ with_object_reference(obj, references) do
34
+ array = []
35
+ obj.each do |value|
36
+ value = call_with_references(value, references)
37
+ array << value unless value.is_a?(RecusiveReferenceError)
38
+ end
39
+ array
37
40
  end
38
- references.delete(obj.object_id)
39
- array
40
41
  elsif @formatter
41
42
  @formatter.format(obj)
42
43
  else
43
44
  obj
44
45
  end
45
46
  end
47
+
48
+ def with_object_reference(obj, references)
49
+ if obj.is_a?(Enumerable)
50
+ return RecusiveReferenceError.new if references.include?(obj.object_id)
51
+ references << obj.object_id
52
+ begin
53
+ yield
54
+ ensure
55
+ references.delete(obj.object_id)
56
+ end
57
+ else
58
+ yield
59
+ end
60
+ end
46
61
  end
47
62
  end
48
63
  end
@@ -237,6 +237,11 @@ module Lumberjack
237
237
  def fatal?
238
238
  level <= FATAL
239
239
  end
240
+
241
+ # Set the log level to fatal.
242
+ def fatal!
243
+ self.level = FATAL
244
+ end
240
245
 
241
246
  # Log an +ERROR+ message. The message can be passed in either the +message+ argument or in a block.
242
247
  def error(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
@@ -247,6 +252,11 @@ module Lumberjack
247
252
  def error?
248
253
  level <= ERROR
249
254
  end
255
+
256
+ # Set the log level to error.
257
+ def error!
258
+ self.level = ERROR
259
+ end
250
260
 
251
261
  # Log a +WARN+ message. The message can be passed in either the +message+ argument or in a block.
252
262
  def warn(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
@@ -257,6 +267,11 @@ module Lumberjack
257
267
  def warn?
258
268
  level <= WARN
259
269
  end
270
+
271
+ # Set the log level to warn.
272
+ def warn!
273
+ self.level = WARN
274
+ end
260
275
 
261
276
  # Log an +INFO+ message. The message can be passed in either the +message+ argument or in a block.
262
277
  def info(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
@@ -267,6 +282,11 @@ module Lumberjack
267
282
  def info?
268
283
  level <= INFO
269
284
  end
285
+
286
+ # Set the log level to info.
287
+ def info!
288
+ self.level = INFO
289
+ end
270
290
 
271
291
  # Log a +DEBUG+ message. The message can be passed in either the +message+ argument or in a block.
272
292
  def debug(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
@@ -277,6 +297,11 @@ module Lumberjack
277
297
  def debug?
278
298
  level <= DEBUG
279
299
  end
300
+
301
+ # Set the log level to debug.
302
+ def debug!
303
+ self.level = DEBUG
304
+ end
280
305
 
281
306
  # Log a message when the severity is not known. Unknown messages will always appear in the log.
282
307
  # The message can be passed in either the +message+ argument or in a block.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lumberjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-06 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec