klogger-logger 1.4.0 → 1.5.0

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/VERSION +1 -1
  4. data/lib/klogger/logger.rb +9 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07fd4a128b55717b068300e71272284d05eaefa3ed32b28955236679a41fa02e
4
- data.tar.gz: c09a76bd59fabc13754f4af45c74373c17dfe19efe17fe2d59b99dff965d770c
3
+ metadata.gz: 545977913e2a22754ceaa46726ed6c1ccaa28c4af5ff3bda20ddf76fbf0783ad
4
+ data.tar.gz: db4cd99e286083d70e768f659cb1446ab4d289a6ed6bbb36ae4f51000771e9ff
5
5
  SHA512:
6
- metadata.gz: f03fe8c99955e64c347d905e0f9225df67706a3c72cfb596b5bf1949234b139f1e56a0b86d849a6b31d6b2b295dd748c2f39feebb0875a2df4940ef6426faeea
7
- data.tar.gz: 3f913bd3e2980d04045e1bc001ea1ecb214f9b5d55066f33c5423ae11b5a8180a7a8bbd0bea9c72d781f48dca4a32e7366f4a80bc837ee77c283825b0724e648
6
+ metadata.gz: 30e4cb6330c169eea17379c012bca5e0b829fe06a4f2bd4597e5d7cde189c981aa514ce4e891ee7e32dcafc3391d8856db440cf759b8b8769abf51ec890f7d40
7
+ data.tar.gz: 39ceffeb22baa21c39f3ef2461a3e469535340e77bbb6795d59fc74078db17b813576c2f9a1df42f476e87cd16d6af295e88ecf3e83d6d047cb60accc9a4bc5f
data/README.md CHANGED
@@ -78,7 +78,7 @@ logger.info { "Hello world!" }
78
78
  logger.info('Result of 1 + 1') { 1 + 1 } # Logs with a message of "Result: 2"
79
79
  ```
80
80
 
81
- ### Loggging exceptions
81
+ ### Logging exceptions
82
82
 
83
83
  Exceptions happen and when they do, you want to know about them. Klogger provides a helper method to log exceptions. These will automatically be logged with the `error` severity.
84
84
 
@@ -197,4 +197,9 @@ end
197
197
  # Create a logger and add the destination
198
198
  logger = Klogger.new(name)
199
199
  logger.add_destination(GraylogDestination.new('graylog.example.com', 12201))
200
+
201
+ # If you only want to send certain data to another block, you can do so
202
+ logger.with_destination(other_destination) do
203
+ # ...
204
+ end
200
205
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.5.0
@@ -36,6 +36,7 @@ module Klogger
36
36
  @destinations = []
37
37
  @group_set = GroupSet.new
38
38
  @silenced = Concurrent::ThreadLocalVar.new { false }
39
+ @block_destinations = Concurrent::ThreadLocalVar.new { [] }
39
40
  @include_group_ids = include_group_ids
40
41
  super(destination)
41
42
  self.formatter = FORMATTERS[formatter].new(highlight: highlight)
@@ -98,6 +99,13 @@ module Klogger
98
99
  @destinations.delete(destination)
99
100
  end
100
101
 
102
+ def with_destination(destination)
103
+ @block_destinations.value << destination
104
+ yield
105
+ ensure
106
+ @block_destinations.value.delete(destination)
107
+ end
108
+
101
109
  def create_tagged_logger(**tags)
102
110
  TaggedLogger.new(self, **tags)
103
111
  end
@@ -142,7 +150,7 @@ module Klogger
142
150
  end
143
151
 
144
152
  def call_destinations(payload, group_ids)
145
- @destinations.each do |destination|
153
+ (@destinations + @block_destinations.value).each do |destination|
146
154
  destination.call(self, payload.dup, group_ids)
147
155
  rescue StandardError => e
148
156
  # If something goes wrong in here, we don't want to break the application
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klogger-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-01 00:00:00.000000000 Z
11
+ date: 2024-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.3.26
108
+ rubygems_version: 3.3.27
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: A simple Ruby logger