cogger 0.7.1 → 0.9.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: 532289692d890ee67b30d2e4b5f725a43c1360ed37e4f58f3cd7885cbac1ac2e
4
+ data.tar.gz: e3e7edbc8ae802edab77418c9770b65edb6d3a152a6db8914902779a1df1b943
5
5
  SHA512:
6
- metadata.gz: cf70a4540105ad59bc4237c9d654e2db5191eeb00b504391a465957b28d7d2fbb7c418969d30762fc8fe0f57ea97893be8980432ab7c2bd0b5643f9fea81ec02
7
- data.tar.gz: d731085187625db4b92c45cc30eaff79c763d47c9e169d3e24a672627f9e2d144b40e4cd49074ce5afb47d05aa1e43c9cd29c0f2c97494d6f91d35e860a8e799
6
+ metadata.gz: 8ccb37f5593cc139a445926860861a3bb03ebb9bab11a077100dba47ec262b1b595ee5a30c501aed280063c42a6fac12ea8c3038b5f773dfb298b20aae3607ef
7
+ data.tar.gz: 66ec62a82933c8063431daf5eb132e68df7c08aeffeaa55754660e2386abb868c627126cd009da08dde5976c853e83adc5567c453ed9454d4f78f3506e6ee382
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
 
@@ -24,9 +23,31 @@ toc::[]
24
23
  * Provides multiple streams so you can log the same information to several outputs at once.
25
24
  * Provides filtering of sensitive information.
26
25
 
27
- == Screenshot
26
+ == Screenshots
28
27
 
29
- image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=1139,height=211,role=focal_point]
28
+ *Emoji*
29
+
30
+ image::https://alchemists.io/images/projects/cogger/screenshots/emoji.png[Emoji,width=150,height=130]
31
+
32
+ *Color*
33
+
34
+ image::https://alchemists.io/images/projects/cogger/screenshots/color.png[Color,width=150,height=125]
35
+
36
+ *Simple*
37
+
38
+ image::https://alchemists.io/images/projects/cogger/screenshots/simple.png[Simple,width=150,height=125]
39
+
40
+ *Detail*
41
+
42
+ image::https://alchemists.io/images/projects/cogger/screenshots/detail.png[Detail,width=350,height=130]
43
+
44
+ *JSON*
45
+
46
+ image::https://alchemists.io/images/projects/cogger/screenshots/json.png[JSON,width=803,height=130]
47
+
48
+ *Rack*
49
+
50
+ image::https://alchemists.io/images/projects/cogger/screenshots/rack.png[Rack,width=534,height=130]
30
51
 
31
52
  == Requirements
32
53
 
@@ -99,13 +120,6 @@ logger.unknown { "demo" } # "demo"
99
120
  logger.any { "demo" } # "demo"
100
121
  ----
101
122
 
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
123
  === Initialization
110
124
 
111
125
  When creating a new logger, you can configure behavior via the following attributes:
@@ -228,7 +242,8 @@ Cogger.emojis
228
242
  # :info => "đŸŸĸ",
229
243
  # :warn => "⚠ī¸ ",
230
244
  # :error => "🛑",
231
- # :fatal => "đŸ”Ĩ"
245
+ # :fatal => "đŸ”Ĩ",
246
+ # :any => "âšĢī¸"
232
247
  # }
233
248
  ----
234
249
 
@@ -356,6 +371,8 @@ logger = Cogger.new formatter: :simple
356
371
  logger = Cogger.new formatter: :rack
357
372
  ----
358
373
 
374
+ ℹī¸ 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.
375
+
359
376
  ==== Color
360
377
 
361
378
  The color formatter is enabled by default and is the equivalent of initializing with either of the following:
@@ -381,8 +398,7 @@ Cogger.aliases
381
398
  # warn: :yellow,
382
399
  # error: :red,
383
400
  # fatal: %i[bold white on_red],
384
- # unknown: %i[bold white],
385
- # any: %i[bold white]
401
+ # any: %i[dim bright_white]
386
402
  # }
387
403
  ----
388
404
 
@@ -401,6 +417,8 @@ Once an alias is added, it can be immediately applied via the template of your f
401
417
  logger = Cogger.new formatter: Cogger::Formatters::Color.new("<mystery>%<message>s</mystery>")
402
418
  ----
403
419
 
420
+ ℹī¸ Much like the simple formatter, any leading or trailing whitespace is automatically after the template has been formatted.
421
+
404
422
  ==== JSON
405
423
 
406
424
  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 +440,20 @@ logger.info verb: "GET", path: "/"
422
440
 
423
441
  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
442
 
443
+ ==== Original
444
+
445
+ 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:
446
+
447
+ [source,ruby]
448
+ ----
449
+ require "logger"
450
+
451
+ logger = Cogger.new formatter: Logger::Formatter.new
452
+ logger.info "demo"
453
+
454
+ # I, [2023-04-11T19:35:51.175733 #84790] INFO -- console: demo
455
+ ----
456
+
425
457
  ==== Custom
426
458
 
427
459
  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 +555,7 @@ This is primarily meant for display/inspection purposes, though.
523
555
 
524
556
  === Testing
525
557
 
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:
558
+ 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
559
 
530
560
  [source,ruby]
531
561
  ----
@@ -542,24 +572,20 @@ class Demo
542
572
  end
543
573
 
544
574
  RSpec.describe Demo do
545
- using Refinements::StringIOs
546
-
547
575
  subject(:demo) { described_class.new logger: }
548
576
 
549
- let(:logger) { Cogger.new io: }
550
- let(:io) { StringIO.new }
577
+ let(:logger) { Cogger.new io: StringIO.new }
551
578
 
552
579
  describe "#say" do
553
580
  it "logs text" do
554
581
  demo.say "test"
555
- expect(io.reread).to include("test")
582
+ expect(logger.reread).to include("test")
556
583
  end
557
584
  end
558
585
  end
559
586
  ----
560
587
 
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.
588
+ 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
589
 
564
590
  == Development
565
591
 
@@ -579,6 +605,8 @@ You can also use the IRB console for direct access to all objects:
579
605
  bin/console
580
606
  ----
581
607
 
608
+ Lastly, there is a `bin/show` script which displays multiple log formats for quick visual reference. This is the same script used to generate the screenshots shown at the top of this document.
609
+
582
610
  == Tests
583
611
 
584
612
  To test, run:
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.9.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/cogger"
@@ -23,7 +23,8 @@ 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 "tone", "~> 0.1"
26
+ spec.add_dependency "refinements", "~> 10.0"
27
+ spec.add_dependency "tone", "~> 0.2"
27
28
  spec.add_dependency "zeitwerk", "~> 2.6"
28
29
 
29
30
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
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
@@ -10,14 +10,14 @@ module Cogger
10
10
  .add_alias(:info, :green)
11
11
  .add_alias(:warn, :yellow)
12
12
  .add_alias(:error, :red)
13
- .add_alias(:fatal, *%i[bold white on_red])
14
- .add_alias(:unknown, *%i[bold white])
15
- .add_alias(:any, *%i[bold white])
13
+ .add_alias(:fatal, :bold, :white, :on_red)
14
+ .add_alias(:any, :dim, :bright_white)
16
15
  .add_emoji(:debug, "🔎")
17
16
  .add_emoji(:info, "đŸŸĸ")
18
17
  .add_emoji(:warn, "⚠ī¸ ")
19
18
  .add_emoji(:error, "🛑")
20
19
  .add_emoji(:fatal, "đŸ”Ĩ")
20
+ .add_emoji(:any, "âšĢī¸")
21
21
  .add_filter(:_csrf)
22
22
  .add_filter(:password)
23
23
  .add_filter(:password_confirmation)
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.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -35,22 +35,36 @@ 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-22 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
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '0.1'
60
+ version: '0.2'
47
61
  type: :runtime
48
62
  prerelease: false
49
63
  version_requirements: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
- version: '0.1'
67
+ version: '0.2'
54
68
  - !ruby/object:Gem::Dependency
55
69
  name: zeitwerk
56
70
  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