lumberjack 1.2.5 → 1.2.6

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: afea02bfb6a11fe77b13b77958097461cc546672f0059cf4a9e5cbb81445a97d
4
- data.tar.gz: d94096a3de319ebce142ca5264b15f62f067dd5dfeaf2a1184a886dfc6a16b80
3
+ metadata.gz: bb579edefef20d72b221b245b502657e3e7b60b61fd2037e6d97ff50577b0d6d
4
+ data.tar.gz: a38ac097040fd058346f2329d2b014d98e465e1f842ca466e52ede4bd5303463
5
5
  SHA512:
6
- metadata.gz: '09250cd1360e5b0a2fcddc4f37504020adfcdcae809edf853c9580f34b1c63a0a834fe4fccb26b6b60b1a03eca2c736deaeeedd6ef5c59ed889be2eeff4ac65e'
7
- data.tar.gz: 0e9c83f1df927ec79d906aaaecfd0a5326217f71b23e537cd4a75232a3a7c0c1f38aee6517ceb3baac09337eeb8fdd72737cfeb31d52c000775e46e8f13c4231
6
+ metadata.gz: 196113e296216a6cf5e5b5914ecc041b9bdb2be71d0847d1bf7bc15cd14aca05a8e2d62f6c2ff397a5323b18a67e714aa19bf3f3eb837c88753254dc5d4226ee
7
+ data.tar.gz: d4ee3d9b4d90464517ce7b8546304b8dfdcb4e709e839d9d828af2b409199bea5d9943860b238156a4c291e1d7cdd12a502dfe365350bce001a6d231d53bd058
@@ -1,3 +1,8 @@
1
+ ## 1.2.6
2
+
3
+ * Fix Logger#tag so it only ads to the current block's logger tags instead of the global tags if called inside a `Logger#tag` block.
4
+ * Add Logger#remove_tag
5
+
1
6
  ## 1.2.5
2
7
 
3
8
  * Fix logic with recursive reference guard in StructuredFormatter so it only suppresses Enumerable references.
File without changes
data/README.md CHANGED
@@ -59,8 +59,10 @@ You can specify tags that will only be applied to the logger in a block as well.
59
59
  ```ruby
60
60
  logger.tag(thread_id: Thread.current.object_id) do
61
61
  logger.info("here") # Will include the `thread_id` tag
62
+ logger.tag(count: 15)
63
+ logger.info("with count") # Will include the `count` tag
62
64
  end
63
- logger.info("there") # Will not include the `thread_id` tag
65
+ logger.info("there") # Will not include the `thread_id` or `count` tag
64
66
  ```
65
67
 
66
68
  You can also set tags to `Proc` objects that will be evaluated when creating a log entry.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.2.6
@@ -67,6 +67,11 @@ module Lumberjack
67
67
  current_context || Context.new
68
68
  end
69
69
  end
70
+
71
+ # Return true if inside a context block.
72
+ def context?
73
+ !!Thread.current[:lumberjack_context]
74
+ end
70
75
 
71
76
  # Return the tags from the current context or nil if there are no tags.
72
77
  def context_tags
@@ -156,10 +156,10 @@ module Lumberjack
156
156
  # logger.add_entry(:warn, "Request took a long time")
157
157
  # logger.add_entry(Logger::DEBUG){"Start processing with options #{options.inspect}"}
158
158
  def add_entry(severity, message, progname = nil, tags = nil)
159
- begin
159
+ begin
160
160
  severity = Severity.label_to_level(severity) unless severity.is_a?(Integer)
161
161
  return true unless device && severity && severity >= level
162
-
162
+
163
163
  return true if Thread.current[:lumberjack_logging]
164
164
  Thread.current[:lumberjack_logging] = true
165
165
 
@@ -237,7 +237,7 @@ module Lumberjack
237
237
  def fatal?
238
238
  level <= FATAL
239
239
  end
240
-
240
+
241
241
  # Set the log level to fatal.
242
242
  def fatal!
243
243
  self.level = FATAL
@@ -252,7 +252,7 @@ module Lumberjack
252
252
  def error?
253
253
  level <= ERROR
254
254
  end
255
-
255
+
256
256
  # Set the log level to error.
257
257
  def error!
258
258
  self.level = ERROR
@@ -267,7 +267,7 @@ module Lumberjack
267
267
  def warn?
268
268
  level <= WARN
269
269
  end
270
-
270
+
271
271
  # Set the log level to warn.
272
272
  def warn!
273
273
  self.level = WARN
@@ -282,7 +282,7 @@ module Lumberjack
282
282
  def info?
283
283
  level <= INFO
284
284
  end
285
-
285
+
286
286
  # Set the log level to info.
287
287
  def info!
288
288
  self.level = INFO
@@ -297,7 +297,7 @@ module Lumberjack
297
297
  def debug?
298
298
  level <= DEBUG
299
299
  end
300
-
300
+
301
301
  # Set the log level to debug.
302
302
  def debug!
303
303
  self.level = DEBUG
@@ -349,16 +349,34 @@ module Lumberjack
349
349
  end
350
350
 
351
351
  # Set a hash of tags on logger. If a block is given, the tags will only be set
352
- # for the duration of the block.
352
+ # for the duration of the block. If this method is called inside such a block,
353
+ # the tags will only be defined on the tags in that block. When the parent block
354
+ # exits, all the tags will be reverted. If there is no block, then the tags will
355
+ # be defined as global and apply to all log statements.
353
356
  def tag(tags, &block)
354
357
  tags = Tags.stringify_keys(tags)
358
+ thread_tags = thread_local_value(:lumberjack_logger_tags)
355
359
  if block
356
- thread_tags = thread_local_value(:lumberjack_logger_tags)
357
- value = (thread_tags ? thread_tags.merge(tags) : tags)
358
- push_thread_local_value(:lumberjack_logger_tags, value, &block)
360
+ merged_tags = (thread_tags ? thread_tags.merge(tags) : tags)
361
+ push_thread_local_value(:lumberjack_logger_tags, merged_tags, &block)
362
+ elsif thread_tags
363
+ thread_tags.merge!(tags)
359
364
  else
360
365
  @tags.merge!(tags)
361
366
  end
367
+ nil
368
+ end
369
+
370
+ # Remove a tag from the current tag context. If this is called inside a block to a
371
+ # call to `tag`, the tags will only be removed for the duration of that block. Otherwise
372
+ # they will be removed from the global tags.
373
+ def remove_tag(*tag_names)
374
+ thread_tags = thread_local_value(:lumberjack_logger_tags)
375
+ if thread_tags
376
+ tag_names.each { |name| thread_tags.delete(name.to_s) }
377
+ else
378
+ tag_names.each { |name| @tags.delete(name.to_s) }
379
+ end
362
380
  end
363
381
 
364
382
  # Return all tags in scope on the logger including global tags set on the Lumberjack
@@ -474,7 +492,7 @@ module Lumberjack
474
492
  sleep(flush_seconds)
475
493
  logger.flush if Time.now - logger.last_flushed_at >= flush_seconds
476
494
  rescue => e
477
- STDERR.puts("Error flushing log: #{e.inspect}")
495
+ $stderr.puts("Error flushing log: #{e.inspect}")
478
496
  end
479
497
  end
480
498
  end
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
11
11
  # Specify which files should be added to the gem when it is released.
12
12
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
13
13
  ignore_files = %w(
14
- .gitignore
15
- .travis.yml
14
+ .
16
15
  Appraisals
17
16
  Gemfile
18
17
  Gemfile.lock
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.5
4
+ version: 1.2.6
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-05-28 00:00:00.000000000 Z
11
+ date: 2020-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -74,7 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - CHANGELOG.md
77
- - MIT_LICENSE
77
+ - MIT_LICENSE.txt
78
78
  - README.md
79
79
  - VERSION
80
80
  - lib/lumberjack.rb