cogger 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +156 -46
- data/cogger.gemspec +2 -1
- data/lib/cogger/client.rb +4 -0
- data/lib/cogger/formatters/color.rb +1 -1
- data/lib/cogger/formatters/json.rb +1 -1
- data/lib/cogger/formatters/kit/sanitizer.rb +1 -1
- data/lib/cogger/formatters/parsers/individual.rb +3 -2
- data/lib/cogger/formatters/processors/color.rb +1 -1
- data/lib/cogger/formatters/simple.rb +1 -1
- data/lib/cogger/hub.rb +21 -13
- data/lib/cogger/registry.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +17 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 864a013edbe00a4cdcc64cdc5f469055c81a39011feb8b2630e028f7388d8169
|
4
|
+
data.tar.gz: f6c9cdb622923a4df16aa1f318c78be864f47d4026cbd1c1245fa3837089df80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3133e82429f654071378e32791985bf923930c441a122725a0f1340d3757c61de1606865a165fe8f562d5340c406f3aea3f767371350f0c8ae46bf47ab337407
|
7
|
+
data.tar.gz: bb01993b5f5408707bb6a1236e4e527460c35972d5d8fcc0d0f580f59824c75dcbb1ed11d0f2c3ee3bf508960710e5b8e4033668530b96134b65cbe8814ee1e2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -6,26 +6,26 @@
|
|
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
|
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
|
|
17
16
|
== Features
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
* Enhances Ruby's default {logger_link} with additional functionality and firepower.
|
19
|
+
* Provides dynamic/specific emoji output.
|
20
|
+
* Provides dynamic/specific colorized output via the {tone_link} gem.
|
21
|
+
* Provides customizable templates which leverage the native {format_link}.
|
22
|
+
* Provides customizable formatters for simple, color, JSON, and/or custom output.
|
23
|
+
* Provides multiple streams so you can log the same information to several outputs at once.
|
24
|
+
* Provides filtering of sensitive information.
|
25
25
|
|
26
26
|
== Screenshot
|
27
27
|
|
28
|
-
image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=
|
28
|
+
image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Console,width=1115,height=716,role=focal_point]
|
29
29
|
|
30
30
|
== Requirements
|
31
31
|
|
@@ -33,11 +33,34 @@ image::https://alchemists.io/images/projects/cogger/screenshots/console.png[Cons
|
|
33
33
|
|
34
34
|
== Setup
|
35
35
|
|
36
|
-
To
|
36
|
+
To install _with_ security, run:
|
37
37
|
|
38
38
|
[source,bash]
|
39
39
|
----
|
40
|
-
|
40
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
41
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
|
42
|
+
gem install cogger --trust-policy HighSecurity
|
43
|
+
----
|
44
|
+
|
45
|
+
To install _without_ security, run:
|
46
|
+
|
47
|
+
[source,bash]
|
48
|
+
----
|
49
|
+
gem install cogger
|
50
|
+
----
|
51
|
+
|
52
|
+
You can also add the gem directly to your project:
|
53
|
+
|
54
|
+
[source,bash]
|
55
|
+
----
|
56
|
+
bundle add cogger
|
57
|
+
----
|
58
|
+
|
59
|
+
Once the gem is installed, you only need to require it:
|
60
|
+
|
61
|
+
[source,ruby]
|
62
|
+
----
|
63
|
+
require "cogger"
|
41
64
|
----
|
42
65
|
|
43
66
|
== Usage
|
@@ -75,18 +98,11 @@ logger.unknown { "demo" } # "demo"
|
|
75
98
|
logger.any { "demo" } # "demo"
|
76
99
|
----
|
77
100
|
|
78
|
-
...or, if you'd like to display all severities at once, use:
|
79
|
-
|
80
|
-
[source,ruby]
|
81
|
-
----
|
82
|
-
%i[debug info warn error fatal unknown any].each { |severity| logger.public_send severity, "demo" }
|
83
|
-
----
|
84
|
-
|
85
101
|
=== Initialization
|
86
102
|
|
87
103
|
When creating a new logger, you can configure behavior via the following attributes:
|
88
104
|
|
89
|
-
* `id`: The program/process ID which shows up in the logs as your `id`. Default: `$PROGRAM_NAME`. For example, if
|
105
|
+
* `id`: The program/process ID which shows up in the logs as your `id`. Default: `$PROGRAM_NAME`. For example, if run within a `demo.rb` script, the `id` would be `"demo"`,
|
90
106
|
* `io`: The input/output stream. This can be `STDOUT/$stdout`, a file/path, or `nil`. Default: `$stdout`.
|
91
107
|
* `level`: The severity level you want to log at. Can be `:debug`, `:info`, `:warn`, `:error`, `:fatal`, or `:unknown`. Default: `:info`.
|
92
108
|
* `formatter`: The formatter to use for formatting your log output. Default: `Cogger::Formatter::Color`. See the _Formatters_ section for more info.
|
@@ -125,7 +141,6 @@ export LOG_LEVEL=WARN
|
|
125
141
|
export LOG_LEVEL=ERROR
|
126
142
|
export LOG_LEVEL=FATAL
|
127
143
|
export LOG_LEVEL=UNKNOWN
|
128
|
-
export LOG_LEVEL=ANY
|
129
144
|
----
|
130
145
|
|
131
146
|
By default, `Cogger` will automatically use whatever is set via the `LOG_LEVEL` environment variable unless overwritten during initialization.
|
@@ -141,33 +156,57 @@ In addition to the above, the {format_link} is further enhanced with the use of
|
|
141
156
|
|
142
157
|
[source,ruby]
|
143
158
|
----
|
144
|
-
# Universal: Dynamic
|
159
|
+
# Universal: Dynamic (color is determined by severity)
|
145
160
|
"<dynamic>%<severity>s %<at>s %<id>s %<message>s</dynamic>"
|
146
161
|
|
147
|
-
# Universal: Specific
|
162
|
+
# Universal: Specific (uses the green color only)
|
148
163
|
"<green>%<severity>s %<at>s %<id>s %<message>s</green>"
|
149
164
|
|
150
|
-
# Individual: Dynamic
|
151
|
-
"%<severity:dynamic>s %<at:
|
165
|
+
# Individual: Dynamic (color is determined by severity)
|
166
|
+
"%<severity:dynamic>s %<at:dynamic>s %<id:dynamic>s %<message:dynamic>s"
|
152
167
|
|
153
|
-
# Individual: Specific
|
168
|
+
# Individual: Specific (uses a rainbow of colors)
|
154
169
|
"%<severity:purple>s %<at:yellow>s %<id:cyan>s %<message:green>s"
|
155
170
|
----
|
156
171
|
|
157
172
|
Here's a detailed breakdown of the above:
|
158
173
|
|
159
174
|
* *Universal*: Applies color universally to the _entire_ template and requires you to:
|
160
|
-
** Wrap your entire template in a and start (`<example>`) and end tag (`</example>`).
|
161
|
-
** Your tag names must either be `<dynamic></dynamic>`, any default color (
|
175
|
+
** Wrap your entire template in a and start (`<example>`) and end tag (`</example>`) which works much like an HTML tag in this context.
|
176
|
+
** Your tag names must either be `<dynamic></dynamic>`, any default color (example: `<green></green>`), or alias (i.e. `<your_alias></your_alias>`) as supported by the {tone_link} gem.
|
162
177
|
* *Individual*: Individual templates allow you to apply color to _specific_ attributes and require you to:
|
163
178
|
** Format your attributes as `attribute:directive`. The colon delimiter is required to separate your attribute for your color choice.
|
164
|
-
** The color value (what follows after the colon) can be `dynamic`, any default color (
|
179
|
+
** The color value (what follows after the colon) can be `dynamic`, any default color (example: `green`), or alias (i.e. `your_alias`) as supported by the {tone_link} gem.
|
165
180
|
|
166
181
|
In addition to the general categorization of universal and individual tags, each support the following directives:
|
167
182
|
|
168
183
|
* *Dynamic*: A dynamic directive means that color will be determined by severity level only. This means if info level is used, the associated color (alias) for info will be applied. Same goes for warn, error, etc.
|
169
184
|
* *Specific*: A specific directive means the color you use will be applied without any further processing regardless of the severity level. This gives you the ability to customize your colors further in situations where dynamic coloring isn't enough.
|
170
185
|
|
186
|
+
At this point, you might have gathered that there are specific keys you can use for the log event metadata in your template and everything else is up to you. This stems from the fact that {logger_link} entries always have the following metadata:
|
187
|
+
|
188
|
+
* `id`: This is the program/process ID you created your logger with (i.e. `Cogger.new id: :demo`).
|
189
|
+
* `severity`: This is the severity at which you messaged your logger (i.e. `logger.info`).
|
190
|
+
* `at`: This is the date/time as which your log event was created.
|
191
|
+
|
192
|
+
This also means if you pass in these same keys as a log event (example: `logger.info id: :bad, at: Time.now, severity: :bogus`) they will be ignored.
|
193
|
+
|
194
|
+
The last key (or keys) is variable and customizable to your needs which is the log event message. Here a couple of examples to illustrate:
|
195
|
+
|
196
|
+
[source,ruby]
|
197
|
+
----
|
198
|
+
# Available as "%<message>s" in your template.
|
199
|
+
logger.info "demo"
|
200
|
+
|
201
|
+
# Available as "%<message>s" in your template.
|
202
|
+
logger.info message: "demo"
|
203
|
+
|
204
|
+
# Available as "%<verb>s" and "%<path>s" in your template.
|
205
|
+
logger.info verb: "GET", path: "/"`
|
206
|
+
----
|
207
|
+
|
208
|
+
💡 In situations where a message hash is logged but the keys of that hash don't match the keys in the template, then an empty message will be logged. This applies to all formatters except the JSON formatter which will log any key/value that doesn't have a `nil` value.
|
209
|
+
|
171
210
|
=== Emojis
|
172
211
|
|
173
212
|
In addition to coloring to your log output, you can add emojis as well. Here are the defaults:
|
@@ -215,6 +254,31 @@ logger.info "demo"
|
|
215
254
|
|
216
255
|
Keep in mind that using a specific, non-dynamic, emoji will _always_ display no matter the current severity level.
|
217
256
|
|
257
|
+
=== Aliases
|
258
|
+
|
259
|
+
Aliases are specific to the {tone_link} gem which allows you _alias_ specific colors/styles via a new name. Here's how you can use them:
|
260
|
+
|
261
|
+
[source,ruby]
|
262
|
+
----
|
263
|
+
Cogger.add_alias :haze, :bold, :white, :on_purple
|
264
|
+
Cogger.aliases
|
265
|
+
----
|
266
|
+
|
267
|
+
The above would add a `:haze` alias which consists of bold white text on a purple background. Once added, you'd then be able to view a list of all default and custom aliases. You can also override an existing alias if you'd like something else.
|
268
|
+
|
269
|
+
Aliases are a powerful way to customize your colors and use short syntax in your templates. Building upon the alias, added above, you'd be able to use it in your templates as follows:
|
270
|
+
|
271
|
+
[source,ruby]
|
272
|
+
----
|
273
|
+
# Universal
|
274
|
+
"<haze>%<message></haze>"
|
275
|
+
|
276
|
+
# Individual
|
277
|
+
"%<message:haze>"
|
278
|
+
----
|
279
|
+
|
280
|
+
Check out the {tone_link} documentation for further examples.
|
281
|
+
|
218
282
|
=== Formatters
|
219
283
|
|
220
284
|
Multiple formatters are provided for you which can be further customized as needed. Here's what is provided by default:
|
@@ -251,7 +315,7 @@ Cogger.formatters
|
|
251
315
|
# }
|
252
316
|
----
|
253
317
|
|
254
|
-
You can add a formatter by providing a
|
318
|
+
You can add a formatter by providing a key, class, and _optional_ template. If a template isn't supplied, then the formatter's default template will be used instead (more on that shortly). Example:
|
255
319
|
|
256
320
|
[source,ruby]
|
257
321
|
----
|
@@ -263,7 +327,7 @@ Cogger.get_formatter :basic
|
|
263
327
|
# [Cogger::Formatters::Simple, "%<severity>s %<message>s"]
|
264
328
|
----
|
265
329
|
|
266
|
-
Symbols or strings can be used interchangeably when adding/getting formatters. As mentioned above, a template doesn't have to be supplied if you want to use the formatter's default template which can be inspected
|
330
|
+
Symbols or strings can be used interchangeably when adding/getting formatters. As mentioned above, a template doesn't have to be supplied if you want to use the formatter's default template which can be inspected as follows:
|
267
331
|
|
268
332
|
[source,ruby]
|
269
333
|
----
|
@@ -271,7 +335,7 @@ Cogger::Formatters::Simple::TEMPLATE
|
|
271
335
|
# "%<message>s"
|
272
336
|
----
|
273
337
|
|
274
|
-
💡 When you find yourself customizing any of the default formatters, you can reduce typing by adding your custom configuration to the registry and then referring to it via
|
338
|
+
💡 When you find yourself customizing any of the default formatters, you can reduce typing by adding your custom configuration to the registry and then referring to it via it's associated key when initializing a new logger.
|
275
339
|
|
276
340
|
==== Simple
|
277
341
|
|
@@ -284,6 +348,8 @@ logger = Cogger.new formatter: :simple
|
|
284
348
|
logger = Cogger.new formatter: :rack
|
285
349
|
----
|
286
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
|
+
|
287
353
|
==== Color
|
288
354
|
|
289
355
|
The color formatter is enabled by default and is the equivalent of initializing with either of the following:
|
@@ -308,13 +374,13 @@ Cogger.aliases
|
|
308
374
|
# info: :green,
|
309
375
|
# warn: :yellow,
|
310
376
|
# error: :red,
|
311
|
-
# fatal: %i[white
|
312
|
-
# unknown: %i[white
|
313
|
-
# any: %i[white
|
377
|
+
# fatal: %i[bold white on_red],
|
378
|
+
# unknown: %i[bold white],
|
379
|
+
# any: %i[bold white]
|
314
380
|
# }
|
315
381
|
----
|
316
382
|
|
317
|
-
This allows a color or combination of color styles (i.e. foreground + background) to be dynamically applied based on log
|
383
|
+
This allows a color -- or combination of color styles (i.e. foreground + background) -- to be dynamically applied based on log severity. You can add additional aliases via:
|
318
384
|
|
319
385
|
[source,ruby]
|
320
386
|
----
|
@@ -329,6 +395,8 @@ Once an alias is added, it can be immediately applied via the template of your f
|
|
329
395
|
logger = Cogger.new formatter: Cogger::Formatters::Color.new("<mystery>%<message>s</mystery>")
|
330
396
|
----
|
331
397
|
|
398
|
+
ℹ️ Much like the simple formatter, any leading or trailing whitespace is automatically after the template has been formatted.
|
399
|
+
|
332
400
|
==== JSON
|
333
401
|
|
334
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:
|
@@ -350,6 +418,20 @@ logger.info verb: "GET", path: "/"
|
|
350
418
|
|
351
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.
|
352
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
|
+
|
353
435
|
==== Custom
|
354
436
|
|
355
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:
|
@@ -372,7 +454,7 @@ class MyFormatter
|
|
372
454
|
end
|
373
455
|
----
|
374
456
|
|
375
|
-
There is no restriction on what dependency you might want to initialize your custom formatter with but -- as a bare minimum -- you'll want to provide a default template and inject the sanitizer which sanitizes the raw log entry into a hash you can interact with in your implementation. The only other requirement is that you must implement `#call` which takes a log entry which is an array of positional arguments (i.e. `severity`, `at`, `id`, `message`) and answers back a formatted string. If you need more examples you can either read the link:https://rubyapi.org/o/logger/formatter#method-i-call[Logger::Formatter] or look at any of the formatters provided within this gem.
|
457
|
+
There is no restriction on what dependency you might want to initialize your custom formatter with but -- as a bare minimum -- you'll want to provide a default template and inject the sanitizer which sanitizes the raw log entry into a hash you can interact with in your implementation. The only other requirement is that you must implement `#call` which takes a log entry which is an array of positional arguments (i.e. `severity`, `at`, `id`, `message`) and answers back a formatted string. If you need more examples you can either read the link:https://rubyapi.org/o/logger/formatter#method-i-call[Logger::Formatter] documentation or look at any of the formatters provided within this gem.
|
376
458
|
|
377
459
|
=== Filters
|
378
460
|
|
@@ -415,11 +497,43 @@ logger.info login: "jayne", password: "secret"
|
|
415
497
|
# {"id":"console","severity":"INFO","at":"2023-04-09 17:33:00 -0600","login":"[FILTERED]","password":"[FILTERED]"}
|
416
498
|
----
|
417
499
|
|
500
|
+
=== Streams
|
501
|
+
|
502
|
+
You can add multiple log streams (outputs) by using:
|
503
|
+
|
504
|
+
[source,ruby]
|
505
|
+
----
|
506
|
+
logger = Cogger.new
|
507
|
+
.add_stream(io: "tmp/demo.log")
|
508
|
+
.add_stream(io: nil)
|
509
|
+
|
510
|
+
logger.info "Demo."
|
511
|
+
----
|
512
|
+
|
513
|
+
The above would log the `"Demo."` message to `$stdout` (i.e. the default stream), to the `tmp/demo.log` file, and to `/dev/null`. All of the attributes you would use to construct your default logger apply to any stream. This also means any custom template/formatter can be applied to your streams. Here's another example:
|
514
|
+
|
515
|
+
[source,ruby]
|
516
|
+
----
|
517
|
+
logger = Cogger.new.add_stream(io: "tmp/demo.log", formatter: :json)
|
518
|
+
logger.info "Demo."
|
519
|
+
----
|
520
|
+
|
521
|
+
In this situation, you'd get colorized output to `$stdout` and JSON output to the `tmp/demo.log` file.
|
522
|
+
|
523
|
+
=== Defaults
|
524
|
+
|
525
|
+
Should you ever need quick access to the defaults, you can use:
|
526
|
+
|
527
|
+
[source,ruby]
|
528
|
+
----
|
529
|
+
Cogger.defaults
|
530
|
+
----
|
531
|
+
|
532
|
+
This is primarily meant for display/inspection purposes, though.
|
533
|
+
|
418
534
|
=== Testing
|
419
535
|
|
420
|
-
When testing
|
421
|
-
logging purposes in order to not pollute your test output but also have a convenient way to see what
|
422
|
-
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:
|
423
537
|
|
424
538
|
[source,ruby]
|
425
539
|
----
|
@@ -436,24 +550,20 @@ class Demo
|
|
436
550
|
end
|
437
551
|
|
438
552
|
RSpec.describe Demo do
|
439
|
-
using Refinements::StringIOs
|
440
|
-
|
441
553
|
subject(:demo) { described_class.new logger: }
|
442
554
|
|
443
|
-
let(:logger) { Cogger.new io: }
|
444
|
-
let(:io) { StringIO.new }
|
555
|
+
let(:logger) { Cogger.new io: StringIO.new }
|
445
556
|
|
446
557
|
describe "#say" do
|
447
558
|
it "logs text" do
|
448
559
|
demo.say "test"
|
449
|
-
expect(
|
560
|
+
expect(logger.reread).to include("test")
|
450
561
|
end
|
451
562
|
end
|
452
563
|
end
|
453
564
|
----
|
454
565
|
|
455
|
-
|
456
|
-
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 also not adding additional noise to 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. 🎉
|
457
567
|
|
458
568
|
== Development
|
459
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.
|
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
|
@@ -18,7 +18,7 @@ module Cogger
|
|
18
18
|
|
19
19
|
def call(*entry)
|
20
20
|
positions = parser.call(template).last.keys
|
21
|
-
attributes = sanitizer.call(*entry)
|
21
|
+
attributes = sanitizer.call(*entry).tap(&:compact!)
|
22
22
|
"#{attributes.slice(*positions).merge!(attributes.except(*positions)).to_json}\n"
|
23
23
|
end
|
24
24
|
|
@@ -14,7 +14,7 @@ module Cogger
|
|
14
14
|
severity, at, id, message = entry
|
15
15
|
|
16
16
|
attributes = if message.is_a? Hash
|
17
|
-
{id:, severity:, at:, **message.except(:id, :severity, :at)}
|
17
|
+
{id:, severity:, at:, message: nil, **message.except(:id, :severity, :at)}
|
18
18
|
else
|
19
19
|
{id:, severity:, at:, message:}
|
20
20
|
end
|
@@ -30,9 +30,10 @@ module Cogger
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def call template
|
33
|
-
return template unless template.match? pattern
|
34
|
-
|
35
33
|
attributes = {}
|
34
|
+
|
35
|
+
return [template, attributes] unless template.match? pattern
|
36
|
+
|
36
37
|
template = sanitize_and_extract template, attributes
|
37
38
|
[template, attributes]
|
38
39
|
end
|
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(**
|
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(**
|
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, :
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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/lib/cogger/registry.rb
CHANGED
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.
|
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-
|
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.
|
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
|