cogger 0.7.1 → 0.8.0

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: 3226b0b30d4c6a4eba83e9aec637de1938ac852f8a7e1bbd3b4a07d501d67920
4
- data.tar.gz: 4e00980079107adbb150c4b03f7d80f63ede92fe6fbbb628642d532dc9d82e9b
3
+ metadata.gz: 864a013edbe00a4cdcc64cdc5f469055c81a39011feb8b2630e028f7388d8169
4
+ data.tar.gz: f6c9cdb622923a4df16aa1f318c78be864f47d4026cbd1c1245fa3837089df80
5
5
  SHA512:
6
- metadata.gz: cf70a4540105ad59bc4237c9d654e2db5191eeb00b504391a465957b28d7d2fbb7c418969d30762fc8fe0f57ea97893be8980432ab7c2bd0b5643f9fea81ec02
7
- data.tar.gz: d731085187625db4b92c45cc30eaff79c763d47c9e169d3e24a672627f9e2d144b40e4cd49074ce5afb47d05aa1e43c9cd29c0f2c97494d6f91d35e860a8e799
6
+ metadata.gz: 3133e82429f654071378e32791985bf923930c441a122725a0f1340d3757c61de1606865a165fe8f562d5340c406f3aea3f767371350f0c8ae46bf47ab337407
7
+ data.tar.gz: bb01993b5f5408707bb6a1236e4e527460c35972d5d8fcc0d0f580f59824c75dcbb1ed11d0f2c3ee3bf508960710e5b8e4033668530b96134b65cbe8814ee1e2
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -6,11 +6,10 @@
6
6
  :logger_link: link:https://rubyapi.org/o/s?q=Logger[Logger]
7
7
  :format_link: link:https://ruby-doc.org/3.2.1/format_specifications_rdoc.html[Format Specification]
8
8
  :pattern_matching_link: link:https://alchemists.io/articles/ruby_pattern_matching[pattern matching]
9
- :refinements_link: link:https://alchemists.io/projects/refinements[Refinements]
10
9
 
11
10
  = Cogger
12
11
 
13
- Cogger is a portmanteau for custom logging (i.e. `[c]ustom + l[ogger] = cogger`) which enhances Ruby's native {logger_link} functionality with additional features such as dynamic emojis, colorized text, structured JSON, multiple outputs, and much more. 🚀
12
+ Cogger is a portmanteau for custom logger (i.e. `[c]ustom + l[ogger] = cogger`) which enhances Ruby's native {logger_link} functionality with additional features such as dynamic emojis, colorized text, structured JSON, multiple outputs, and much more. 🚀
14
13
 
15
14
  toc::[]
16
15
 
@@ -26,7 +25,7 @@ toc::[]
26
25
 
27
26
  == Screenshot
28
27
 
29
- image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=1139,height=211,role=focal_point]
28
+ image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=1115,height=716,role=focal_point]
30
29
 
31
30
  == Requirements
32
31
 
@@ -99,13 +98,6 @@ logger.unknown { "demo" } # "demo"
99
98
  logger.any { "demo" } # "demo"
100
99
  ----
101
100
 
102
- ...or, if you'd like to display all severities at once, use:
103
-
104
- [source,ruby]
105
- ----
106
- %i[debug info warn error fatal unknown any].each { |severity| logger.public_send severity, "demo" }
107
- ----
108
-
109
101
  === Initialization
110
102
 
111
103
  When creating a new logger, you can configure behavior via the following attributes:
@@ -356,6 +348,8 @@ logger = Cogger.new formatter: :simple
356
348
  logger = Cogger.new formatter: :rack
357
349
  ----
358
350
 
351
+ ℹī¸ Any leading or trailing whitespace is automatically removed after the template has been formatted in order to account for template attributes that might be `nil` or empty strings so you don't have visual indentation in your output.
352
+
359
353
  ==== Color
360
354
 
361
355
  The color formatter is enabled by default and is the equivalent of initializing with either of the following:
@@ -401,6 +395,8 @@ Once an alias is added, it can be immediately applied via the template of your f
401
395
  logger = Cogger.new formatter: Cogger::Formatters::Color.new("<mystery>%<message>s</mystery>")
402
396
  ----
403
397
 
398
+ ℹī¸ Much like the simple formatter, any leading or trailing whitespace is automatically after the template has been formatted.
399
+
404
400
  ==== JSON
405
401
 
406
402
  This formatter is similar in behavior to the _simple_ formatter except the template allows you to order the layout of your keys only. All other information is ignored. To use:
@@ -422,6 +418,20 @@ logger.info verb: "GET", path: "/"
422
418
 
423
419
  Your template can be a full or partial match of keys. If no keys match what is defined in the template, then the original order of the keys will be used instead.
424
420
 
421
+ ==== Original
422
+
423
+ Should you wish to use the original formatter as provided by original/native {logger_link}, you can get that behavior by specifying it as your preferred formatter. Example:
424
+
425
+ [source,ruby]
426
+ ----
427
+ require "logger"
428
+
429
+ logger = Cogger.new formatter: Logger::Formatter.new
430
+ logger.info "demo"
431
+
432
+ # I, [2023-04-11T19:35:51.175733 #84790] INFO -- console: demo
433
+ ----
434
+
425
435
  ==== Custom
426
436
 
427
437
  Should none of the built-in formatters be to your liking, you can implement, use, and/or register a custom formatter as well. The most minimum, bare bones, skeleton would be:
@@ -523,9 +533,7 @@ This is primarily meant for display/inspection purposes, though.
523
533
 
524
534
  === Testing
525
535
 
526
- When testing the Cogger client, you might find it convenient to use `StringIO`, or a file, for
527
- logging purposes in order to not pollute your test output but also have a convenient way to see what
528
- was logged. Example:
536
+ When testing, you might find it convenient to rewind and read from the stream you are writing too (i.e. `IO`, `StringIO`, `File`). For instance, here is an example where I inject the default logger into my `Demo` class and then, for testing purposes, create a new logger to be injected which only logs to `StringIO` so I can buffer and read for test verification:
529
537
 
530
538
  [source,ruby]
531
539
  ----
@@ -542,24 +550,20 @@ class Demo
542
550
  end
543
551
 
544
552
  RSpec.describe Demo do
545
- using Refinements::StringIOs
546
-
547
553
  subject(:demo) { described_class.new logger: }
548
554
 
549
- let(:logger) { Cogger.new io: }
550
- let(:io) { StringIO.new }
555
+ let(:logger) { Cogger.new io: StringIO.new }
551
556
 
552
557
  describe "#say" do
553
558
  it "logs text" do
554
559
  demo.say "test"
555
- expect(io.reread).to include("test")
560
+ expect(logger.reread).to include("test")
556
561
  end
557
562
  end
558
563
  end
559
564
  ----
560
565
 
561
- Notice that when testing the instance of `Demo` and injecting a logger which logs to a string I/O
562
- object, you can conveniently _reread_ the string -- provided by the {refinements_link} gem -- to see what was logged. This makes your specs easier to write while avoiding additional noise in your test suite's output.
566
+ The ability to `#reread` is only available for the default (first) stream and doesn't work with any additional streams that you add to your logger. That said, this does make it easy to test the `Demo` implementation while also keeping your test suite output clean at the same time. 🎉
563
567
 
564
568
  == Development
565
569
 
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 = "0.7.1"
5
+ spec.version = "0.8.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/cogger"
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
25
  spec.required_ruby_version = "~> 3.2"
26
+ spec.add_dependency "refinements", "~> 10.0"
26
27
  spec.add_dependency "tone", "~> 0.1"
27
28
  spec.add_dependency "zeitwerk", "~> 2.6"
28
29
 
data/lib/cogger/client.rb CHANGED
@@ -14,7 +14,11 @@ module Cogger
14
14
 
15
15
  delegate %i[formatter level progname debug info warn error fatal unknown] => :logger
16
16
 
17
+ # :reek:TooManyStatements
17
18
  def initialize logger = Logger.new($stdout), color: Cogger.color, **attributes
19
+ warn "#{self.class}##{__method__} is deprecated, use `Cogger.new` instead.",
20
+ category: :deprecated
21
+
18
22
  @logger = logger
19
23
  @color = color
20
24
  @attributes = attributes
@@ -13,7 +13,7 @@ module Cogger
13
13
 
14
14
  def call(*entry)
15
15
  updated_template, attributes = processor.call(template, *entry)
16
- "#{format(updated_template, **attributes)}\n"
16
+ "#{format(updated_template, **attributes).tap(&:strip!)}\n"
17
17
  end
18
18
 
19
19
  private
@@ -11,7 +11,7 @@ module Cogger
11
11
  @sanitizer = sanitizer
12
12
  end
13
13
 
14
- def call(*entry) = "#{format template, sanitizer.call(*entry)}\n"
14
+ def call(*entry) = "#{format(template, sanitizer.call(*entry)).tap(&:strip!)}\n"
15
15
 
16
16
  private
17
17
 
data/lib/cogger/hub.rb CHANGED
@@ -1,20 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "logger"
4
+ require "refinements/hashes"
5
+ require "refinements/loggers"
4
6
 
5
7
  module Cogger
6
8
  # Loads configuration and simultaneously sends messages to multiple streams.
9
+ # :reek:TooManyInstanceVariables
7
10
  class Hub
11
+ using Refinements::Loggers
12
+ using Refinements::Hashes
13
+
8
14
  def initialize(registry: Cogger, model: Configuration.new, **attributes)
9
15
  @registry = registry
10
- @configuration = model.with(**transform(attributes))
16
+ @configuration = model.with(**find_formatter(attributes))
17
+ @primary = configuration.to_logger
18
+ @streams = [@primary]
11
19
  @mutex = Mutex.new
12
- @streams = [configuration.to_logger]
13
20
  end
14
21
 
15
22
  def add_stream **attributes
16
23
  attributes[:id] = configuration.id
17
- streams.append configuration.with(**transform(attributes)).to_logger
24
+ streams.append configuration.with(**find_formatter(attributes)).to_logger
18
25
  self
19
26
  end
20
27
 
@@ -32,24 +39,25 @@ module Cogger
32
39
 
33
40
  alias any unknown
34
41
 
42
+ def reread = primary.reread
43
+
35
44
  def inspect
36
45
  %(#<#{self.class} #{configuration.inspect.delete_prefix! "#<Cogger::Configuration "})
37
46
  end
38
47
 
39
48
  private
40
49
 
41
- attr_reader :registry, :configuration, :mutex, :streams
42
-
43
- # :reek:FeatureEnvy
44
- # :reek:TooManyStatements
45
- def transform attributes
46
- value = attributes[:formatter]
50
+ attr_reader :registry, :configuration, :primary, :streams, :mutex
47
51
 
48
- return attributes unless value.is_a?(Symbol) || value.is_a?(String)
52
+ def find_formatter attributes
53
+ attributes.transform_with!(
54
+ formatter: lambda do |value|
55
+ return value unless value.is_a?(Symbol) || value.is_a?(String)
49
56
 
50
- formatter, template = registry.get_formatter value
51
- attributes[:formatter] = template ? formatter.new(template) : formatter.new
52
- attributes
57
+ formatter, template = registry.get_formatter value
58
+ template ? formatter.new(template) : formatter.new
59
+ end
60
+ )
53
61
  end
54
62
 
55
63
  # :reek:TooManyStatements
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: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,8 +35,22 @@ cert_chain:
35
35
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
36
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
37
  -----END CERTIFICATE-----
38
- date: 2023-04-11 00:00:00.000000000 Z
38
+ date: 2023-04-12 00:00:00.000000000 Z
39
39
  dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: refinements
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '10.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: tone
42
56
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
133
  - !ruby/object:Gem::Version
120
134
  version: '0'
121
135
  requirements: []
122
- rubygems_version: 3.4.10
136
+ rubygems_version: 3.4.12
123
137
  signing_key:
124
138
  specification_version: 4
125
139
  summary: A customizable logger.
metadata.gz.sig CHANGED
Binary file