cogger 2.2.0 → 2.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c81fa9c3fdd3ce5ef1db012304946e95dd84c5c9087f5a82b6029f507f278c51
4
- data.tar.gz: fb40393d822afe21906b559bca98bdf602875b2d78ca38a843a58ad34154d4f6
3
+ metadata.gz: 051cbeb63381e6680f86fd1b73a1e6648d6ecc1befc37824d0425cbb12d0fb63
4
+ data.tar.gz: 8772b28a29157d2f023096eaf40ba28c252888e3430e5ddc673ade49888b7da2
5
5
  SHA512:
6
- metadata.gz: 1975f4568ca48b1d0f6851a66d255b43cc57c79849ab6edafc621f2705ffbe6ae116aad3cc76d024ab67cd5b17d431795fddda0de9083062876192176fe71d3a
7
- data.tar.gz: 7f0c08112e4510dd7120e5e2c4ecd8cb98a3a35fa13087ebd6252e9367d81574a46e44365697637a3b4bc2e9de9c6823b897ff8ecc1d13d06aef002ec947dd55
6
+ metadata.gz: 4b290ebea636e3744c68dd07c1cd37bd310fa3c99600a8b7a32ed93dcdcc651559ff718fcfe43446c7bad91772ba25eb4bb60bfe0ff9f2c6f85d8158dc58c9c1
7
+ data.tar.gz: 163afc50ba9118ab76f2ff75f351b4d2b60992b29f317bbfab218e310ada42890fec1e5cfed6993bde0421d67126b65038adbe7b81791f062c07ae82e32c3143
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -182,7 +182,7 @@ export LOG_LEVEL=fatal
182
182
  export LOG_LEVEL=unknown
183
183
  ----
184
184
 
185
- While downcase is preferred for each log level value, you can use upcased values as well. If the `LOG_LEVEL` environment variable is not set, `Cogger` will fall back to `"info"` unless overwritten during initialization. Example: `Cogger.new level: :debug`. Otherwise, an invalid log level will result in an `ArgumentError`.
185
+ While lower case is preferred for each log level value, you can use upper case values as well. If the `LOG_LEVEL` environment variable is not set, `Cogger` will fall back to `"info"` unless overwritten during initialization. Example: `Cogger.new level: :debug`. Otherwise, an invalid log level will result in an `ArgumentError`.
186
186
 
187
187
  === Mutations
188
188
 
@@ -457,7 +457,7 @@ Additional keys as provided by your message hash and/or tags can be customized a
457
457
  Template keys, emojis, and elements do have a few restrictions:
458
458
 
459
459
  * Use the special `emoji` key to provide dynamic or specific emoji logging.
460
- * Use the special `tags` key to provide tagged logging. More information on tags can be found later in this document.
460
+ * Use the special `tags` key to provide tagged logging. For more information, the _Tags_ section below.
461
461
  * Avoid supplying the same keys as the default keys. Example: `logger.info id: :bad, at: Time.now, level: :bogus`. This is because these keys will be ignored. In other words, you can't _override_ the default keys.
462
462
  * Avoid wrapping keys and/or emojis in elements because nesting isn't supported and can lead to strange output. Example: `<green>%<emoji:error>s %<id:dynamic>s</green>`.
463
463
  * Avoid wrapping elements within elements because nesting isn't supported and can lead to strange output. Example: `<dynamic><cyan>%<message>s</cyan></dynamic>`.
@@ -757,8 +757,7 @@ logger.info "Demo", tags: ["WEB", "PRIMARY", {service: :api, demo: true}]
757
757
  # "level":"INFO",
758
758
  # "at":"2023-12-10T18:44:32.723+00:00",
759
759
  # "message":"Demo",
760
- # "tags":["WEB",
761
- # "PRIMARY"],
760
+ # "tags":["WEB", "PRIMARY"],
762
761
  # "service":"api",
763
762
  # "demo":true
764
763
  # }
@@ -929,6 +928,7 @@ As you can see, tags are highly versatile. That said, the following guidelines a
929
928
  * Prefer consistent tag names by using tags that are not synonymous or ambiguous.
930
929
  * Prefer using tags by feature rather than things like environments. Examples: API, DB, MAILER.
931
930
  * Prefer the JSON formatter for structured metadata instead of tags. Logging JSON formatted messages with tags will work but sticking with a traditional hash, instead of tags, will probably serve you better.
931
+ * Avoid using `id`, `level`, `at`, and/or `message` as hash keys since those are reserved keys and will be rejected if supplied.
932
932
 
933
933
  === Filters
934
934
 
@@ -970,14 +970,25 @@ You can add multiple log streams (outputs) by using:
970
970
 
971
971
  [source,ruby]
972
972
  ----
973
+ require "stringio"
974
+
975
+ buffer = StringIO.new
973
976
  logger = Cogger.new
977
+ .add_stream(io: buffer)
974
978
  .add_stream(io: "tmp/demo.log")
975
979
  .add_stream(io: nil)
976
980
 
977
981
  logger.info "Demo."
978
982
  ----
979
983
 
980
- The above would log the `"Demo."` message to `$stdout` -- the default stream -- to the `tmp/demo.log` file, and to `/dev/null`. All attributes used to construct your default logger apply to all additional streams unless customized further. This means any custom template/formatter can be applied to your streams. Example:
984
+ The above would log `"Demo."` to:
985
+
986
+ * To `$stdout` (the default stream which is your console).
987
+ * To the StringIO `buffer` where you can use `buffer.string` to view content.
988
+ * To the `tmp/demo.log` file where you can use `cat tmp/demo.log` to view content.
989
+ * To `/dev/null` which immediately ignores all writes.
990
+
991
+ All attributes used to construct your default logger apply to all additional streams unless customized further. This means any custom template/formatter can be applied to your streams. Example:
981
992
 
982
993
  [source,ruby]
983
994
  ----
data/cogger.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "cogger"
5
- spec.version = "2.2.0"
5
+ spec.version = "2.3.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/cogger"
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "logger", "~> 1.7"
29
29
  spec.add_dependency "refinements", "~> 14.0"
30
30
  spec.add_dependency "tone", "~> 3.0"
31
- spec.add_dependency "zeitwerk", "~> 2.7"
31
+ spec.add_dependency "zeitwerk", "~> 2.8"
32
32
 
33
33
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
34
34
  spec.files = Dir["*.gemspec", "lib/**/*"]
data/lib/cogger/tag.rb CHANGED
@@ -5,18 +5,24 @@ require "refinements/hash"
5
5
 
6
6
  module Cogger
7
7
  # Models a tag which may consist of an array and/or hash.
8
- Tag = Data.define :singles, :pairs do
8
+ Tag = Data.define :singles, :pairs, :exclusions do
9
9
  using Refinements::Hash
10
10
 
11
- def self.for(*bag)
12
- bag.each.with_object new do |item, tag|
11
+ def self.for(*bag) = new(**reduce(bag))
12
+
13
+ def self.reduce bag
14
+ bag.each.with_object({singles: [], pairs: {}}) do |item, all|
13
15
  value = item.is_a?(Proc) ? item.call : item
14
- value.is_a?(Hash) ? tag.pairs.merge!(value) : tag.singles.append(value)
16
+ value.is_a?(Hash) ? all[:pairs].merge!(value) : all[:singles].append(value)
15
17
  end
16
18
  end
17
19
 
18
- def initialize singles: [], pairs: {}
19
- super
20
+ private_class_method :reduce
21
+
22
+ def initialize singles: [], pairs: {}, exclusions: %w[id level at message]
23
+ filtered_pairs = pairs.reject { |key, _| exclusions.include? key.to_s }
24
+
25
+ super singles:, pairs: filtered_pairs, exclusions:
20
26
  end
21
27
 
22
28
  def empty? = singles.empty? && pairs.empty?
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -97,14 +97,14 @@ dependencies:
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '2.7'
100
+ version: '2.8'
101
101
  type: :runtime
102
102
  prerelease: false
103
103
  version_requirements: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - "~>"
106
106
  - !ruby/object:Gem::Version
107
- version: '2.7'
107
+ version: '2.8'
108
108
  email:
109
109
  - brooke@alchemists.io
110
110
  executables: []
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  - !ruby/object:Gem::Version
176
176
  version: '0'
177
177
  requirements: []
178
- rubygems_version: 4.0.10
178
+ rubygems_version: 4.0.12
179
179
  specification_version: 4
180
180
  summary: A customizable and feature rich logger.
181
181
  test_files: []
metadata.gz.sig CHANGED
Binary file