lumberjack 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 937acfbe9675acf0eecd3fa034e0818952967b00471e365d2ea3f0ab7fafa4d1
4
- data.tar.gz: 0b82a010a7c4265c92cec3e7d5b0ffcb5f4ac5e151c7e1e8ee28ac8d0b3adf9b
3
+ metadata.gz: 6869d51bf38cc7ee1aad46005d947c5313bf58064da86cbd44ab5ca69dd04a71
4
+ data.tar.gz: 2817b2ace992f96770a16f1f5d6133a06f1e7277dfe236deb31d8fcad9934d39
5
5
  SHA512:
6
- metadata.gz: 42d94b2e4c35ded1291262acf02e3d886c9b5acc2d26bd40d5d6884ebced0658d8b7baeb83aa402f700a294cbdba05491aaabff4d9f7df9bb03c5edd3954f2a4
7
- data.tar.gz: 2ddcf64ed40c77e57cc8152aba8241c6f92c2668d3a6f6aa58c674e46e35cb0e1a78491d24588d67fbdc13d1ce9904c5a200426948367fe8d9ef4b50bd00b23e
6
+ metadata.gz: 6419348e19de6901892b35118ebc4405a773706b817d5c3c443f733973a977ad3be171b1f736b81334d9173cae5271799e267917284d3a28459349bc0cfc76f7
7
+ data.tar.gz: 5dca009d8cc55ea4044e9eba50df1ebba04351d019c3322b733ae01fc0d250f29d3a9f625c67da3549a0a7ebf8487a465f1ff4cca1ccfccf662f1cbccc4629cd
@@ -1,3 +1,7 @@
1
+ ## 1.1.1
2
+
3
+ * Replace Procs in tag values with the value of calling the Proc in log entries.
4
+
1
5
  ## 1.1.0
2
6
 
3
7
  * Change Lumberjack::Logger to inherit from ::Logger
data/README.md CHANGED
@@ -63,6 +63,16 @@ end
63
63
  logger.info("there") # Will not include the `thread_id` tag
64
64
  ```
65
65
 
66
+ You can also set tags to `Proc` objects that will be evaluated when creating a log entry.
67
+
68
+ ```ruby
69
+ logger.tag(thread_id: lambda { Thread.current.object_id })
70
+ Thread.new do
71
+ logger.info("inside thread") # Will include the `thread_id` tag with id of the spawned thread
72
+ end
73
+ logger.info("outside thread") # Will include the `thread_id` tag with id of the main thread
74
+ ```
75
+
66
76
  Finally, you can specify a logging context with tags that apply within a block to all loggers.
67
77
 
68
78
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -153,6 +153,7 @@ module Lumberjack
153
153
  tags = current_tags.merge(Tags.stringify_keys(tags))
154
154
  end
155
155
  end
156
+ tags = Tags.expand_runtime_values(tags)
156
157
 
157
158
  entry = LogEntry.new(time, severity, message, progname, $$, tags)
158
159
  write_to_device(entry)
@@ -19,6 +19,24 @@ module Lumberjack
19
19
  copy
20
20
  end
21
21
  end
22
+
23
+ # Ensure keys are strings and expand any values in a hash that are Proc's by calling them and replacing
24
+ # the value with the result. This allows setting global tags with runtime values.
25
+ def expand_runtime_values(hash)
26
+ return nil if hash.nil?
27
+ if hash.all? { |key, value| key.is_a?(String) && !value.is_a?(Proc) }
28
+ return hash
29
+ end
30
+
31
+ copy = {}
32
+ hash.each do |key, value|
33
+ if value.is_a?(Proc) && (value.arity == 0 || value.arity == -1)
34
+ value = value.call
35
+ end
36
+ copy[key.to_s] = value
37
+ end
38
+ copy
39
+ end
22
40
  end
23
41
  end
24
42
  end
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.1.0
4
+ version: 1.1.1
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-01-05 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec