cogger 1.3.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +59 -7
- data/cogger.gemspec +2 -2
- data/lib/cogger/configuration.rb +4 -2
- data/lib/cogger/entry.rb +20 -2
- data/lib/cogger/formatters/abstract.rb +2 -2
- data/lib/cogger/formatters/parsers/position.rb +2 -4
- data/lib/cogger/hub.rb +2 -4
- data/lib/cogger/registry.rb +27 -6
- data.tar.gz.sig +0 -0
- metadata +4 -4
- 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: 492646c716b64bbf80f9aa93bf0092220068b00ef8abe89bc8baaaef9f3464f7
|
4
|
+
data.tar.gz: 834d46200c376ffc6c538e229ae5f5ca4b44ba0beed3c2724e5585ebc8aca642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc80eb9f305539d61932c5c5a95e01dfeb18ee76dee502049aabac4073ab37ee33ef45dbd73e7df6637b23f5b4e623df0e144e01a64755c646513bfe3dd45e0c
|
7
|
+
data.tar.gz: 7c52fdfd07d8e2595f2f02e28b9546c4b7d389a9b7ae3f32feb686d8719a07533581f5b5ea28c0a0ab2684e457d7a3a8cc6e8b49ebfa0831deb6dbb1ffda5d95
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -236,8 +236,7 @@ To add multiple custom emojis, you can chain messages together when registering
|
|
236
236
|
|
237
237
|
[source,ruby]
|
238
238
|
----
|
239
|
-
Cogger.
|
240
|
-
.add_emoji :favorite, "βοΈ"
|
239
|
+
Cogger.add_emojis tada: "π", favorite: "βοΈ"
|
241
240
|
----
|
242
241
|
|
243
242
|
If you always want to use the _same_ emoji, you could use the emoji formatter with a specific template:
|
@@ -282,6 +281,26 @@ Aliases are a powerful way to customize colors via concise syntax in your templa
|
|
282
281
|
|
283
282
|
π‘ Aliases are used by the color and emoji formatters so check out the {tone_link} documentation and/or _Templates_ and _Formatters_ sections below to learn more.
|
284
283
|
|
284
|
+
=== Encodings
|
285
|
+
|
286
|
+
All messages use UTF-8 encoding. Any unknown character will show up as a question mark. Example:
|
287
|
+
|
288
|
+
[source,ruby]
|
289
|
+
----
|
290
|
+
logger = Cogger.new
|
291
|
+
bad = "b\xE9d".dup.force_encoding "ASCII-8BIT"
|
292
|
+
|
293
|
+
logger.info bad # "b?d"
|
294
|
+
logger.info { bad } # "b?d"
|
295
|
+
----
|
296
|
+
|
297
|
+
The underlying implementation uses the following to produce the logs shown above:
|
298
|
+
|
299
|
+
[source,ruby]
|
300
|
+
----
|
301
|
+
message.encode "UTF-8", invalid: :replace, undef: :replace, replace: "?"
|
302
|
+
----
|
303
|
+
|
285
304
|
=== Templates
|
286
305
|
|
287
306
|
Templates are used by all formatters and adhere to an _enhanced_ version of the {format_link} as used by `Kernel#format`. Hereβs what is provided by default:
|
@@ -596,7 +615,7 @@ This allows an emoji to be dynamically applied based on log level. You can add o
|
|
596
615
|
|
597
616
|
[source,ruby]
|
598
617
|
----
|
599
|
-
Cogger.
|
618
|
+
Cogger.add_emojis warn: "π‘"
|
600
619
|
----
|
601
620
|
|
602
621
|
Once an alias is added/updated, it can be immediately applied via the template of your formatter. Example:
|
@@ -746,6 +765,41 @@ logger.info "Demo", tags: ["WEB", "PRIMARY", {service: :api, demo: true}]
|
|
746
765
|
|
747
766
|
Notice, with the above, that the single tags of `WEB` and `PRIMARY` show up in the `tags` array while the `:service` and `:demo` keys show up at the top level of the hash. Since the `:tags`, `:service`, `:demo` keys are normal keys, like any key in your JSON output, this means you can use a custom template to arrange the order of these keys if you don't like the default.
|
748
767
|
|
768
|
+
A block can be used with a string or hash for content. Example:
|
769
|
+
|
770
|
+
[source,ruby]
|
771
|
+
----
|
772
|
+
logger = Cogger.new formatter: :json
|
773
|
+
|
774
|
+
logger.info { "Demo" }
|
775
|
+
# {
|
776
|
+
# "id":"console",
|
777
|
+
# "level":"INFO",
|
778
|
+
# "at":"2025-08-03T13:37:58.227-06:00",
|
779
|
+
# "message":"Demo"
|
780
|
+
# }
|
781
|
+
|
782
|
+
logger.info { {message: :demo, weight: 0.2} }
|
783
|
+
# {
|
784
|
+
# "id":"console",
|
785
|
+
# "level":"INFO",
|
786
|
+
# "at":"2025-08-03T13:39:32.438-06:00",
|
787
|
+
# "message":"demo",
|
788
|
+
# "weight":0.2
|
789
|
+
# }
|
790
|
+
|
791
|
+
logger.info(tags: %w[WEB PRIMARY]) { {message: :demo, weight: 0.2} }
|
792
|
+
# {
|
793
|
+
# "id":"console",
|
794
|
+
# "level":"INFO",
|
795
|
+
# "at":"2025-08-03T13:42:22.869-06:00",
|
796
|
+
# "message":"demo",
|
797
|
+
# "tags":["WEB",
|
798
|
+
# "PRIMARY"],
|
799
|
+
# "weight":0.2
|
800
|
+
# }
|
801
|
+
----
|
802
|
+
|
749
803
|
==== Rack
|
750
804
|
|
751
805
|
This formatter is the _Simple_ formatter with a different template and can be configured as follows:
|
@@ -888,9 +942,7 @@ To add filters, use:
|
|
888
942
|
|
889
943
|
[source,ruby]
|
890
944
|
----
|
891
|
-
Cogger.
|
892
|
-
.add_filter "email"
|
893
|
-
|
945
|
+
Cogger.add_filters :login, "email"
|
894
946
|
Cogger.filters # #<Set: {:login, :email}>
|
895
947
|
----
|
896
948
|
|
@@ -898,7 +950,7 @@ Symbols and strings can be used interchangeably but are stored as symbols since
|
|
898
950
|
|
899
951
|
[source,ruby]
|
900
952
|
----
|
901
|
-
Cogger.
|
953
|
+
Cogger.add_filters :password
|
902
954
|
logger = Cogger.new formatter: :json
|
903
955
|
logger.info login: "jayne", password: "secret"
|
904
956
|
|
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 = "1.
|
5
|
+
spec.version = "1.5.0"
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
8
8
|
spec.homepage = "https://alchemists.io/projects/cogger"
|
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.required_ruby_version = "~> 3.4"
|
26
26
|
spec.add_dependency "core", "~> 2.0"
|
27
27
|
spec.add_dependency "logger", "~> 1.7"
|
28
|
-
spec.add_dependency "refinements", "~> 13.
|
28
|
+
spec.add_dependency "refinements", "~> 13.5"
|
29
29
|
spec.add_dependency "tone", "~> 2.0"
|
30
30
|
spec.add_dependency "zeitwerk", "~> 2.7"
|
31
31
|
|
data/lib/cogger/configuration.rb
CHANGED
@@ -18,7 +18,8 @@ module Cogger
|
|
18
18
|
:size,
|
19
19
|
:suffix,
|
20
20
|
:entry,
|
21
|
-
:logger
|
21
|
+
:logger,
|
22
|
+
:mutex
|
22
23
|
) do
|
23
24
|
using Refinements::Array
|
24
25
|
|
@@ -33,7 +34,8 @@ module Cogger
|
|
33
34
|
size: 1_048_576,
|
34
35
|
suffix: "%Y-%m-%d",
|
35
36
|
entry: Entry,
|
36
|
-
logger: Logger
|
37
|
+
logger: Logger,
|
38
|
+
mutex: Mutex.new
|
37
39
|
super.tap { tags.freeze }
|
38
40
|
end
|
39
41
|
|
data/lib/cogger/entry.rb
CHANGED
@@ -5,11 +5,13 @@ require "core"
|
|
5
5
|
module Cogger
|
6
6
|
# Defines a log entry which can be formatted for output.
|
7
7
|
Entry = Data.define :id, :level, :at, :message, :tags, :datetime_format, :payload do
|
8
|
-
def self.for(message = nil, **payload)
|
8
|
+
def self.for(message = nil, **payload, &)
|
9
|
+
content = block_given? ? yield : message
|
10
|
+
|
9
11
|
new id: payload.delete(:id) || Program.call,
|
10
12
|
level: (payload.delete(:level) || "INFO").upcase,
|
11
13
|
at: payload.delete(:at) || ::Time.now,
|
12
|
-
message: (
|
14
|
+
message: sanitize!(content, payload),
|
13
15
|
tags: Array(payload.delete(:tags)),
|
14
16
|
datetime_format: payload.delete(:datetime_format) || DATETIME_FORMAT,
|
15
17
|
payload:
|
@@ -26,6 +28,22 @@ module Cogger
|
|
26
28
|
}
|
27
29
|
end
|
28
30
|
|
31
|
+
def self.sanitize! content, payload
|
32
|
+
body = if content.is_a? Hash
|
33
|
+
content.delete(:message).tap { payload.merge! content }
|
34
|
+
else
|
35
|
+
content
|
36
|
+
end
|
37
|
+
|
38
|
+
if body.is_a? String
|
39
|
+
body.encode "UTF-8", invalid: :replace, undef: :replace, replace: "?"
|
40
|
+
else
|
41
|
+
body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private_class_method :sanitize!
|
46
|
+
|
29
47
|
def initialize id: Program.call,
|
30
48
|
level: "INFO",
|
31
49
|
at: ::Time.now,
|
@@ -23,8 +23,8 @@ module Cogger
|
|
23
23
|
|
24
24
|
protected
|
25
25
|
|
26
|
-
def sanitize entry,
|
27
|
-
entry.public_send(
|
26
|
+
def sanitize entry, method
|
27
|
+
entry.public_send(method).tap do |attributes|
|
28
28
|
filter attributes
|
29
29
|
attributes.transform_values! { |value| format_time value, format: entry.datetime_format }
|
30
30
|
end
|
@@ -10,7 +10,7 @@ module Cogger
|
|
10
10
|
? # Flag, width, or precision.
|
11
11
|
< # Reference start.
|
12
12
|
(?<name>\w+) # Name.
|
13
|
-
(
|
13
|
+
(?::\w+)? # Optional delimiter and directive.
|
14
14
|
> # Reference end.
|
15
15
|
? # Specifier.
|
16
16
|
/x
|
@@ -19,10 +19,8 @@ module Cogger
|
|
19
19
|
@pattern = pattern
|
20
20
|
end
|
21
21
|
|
22
|
-
# :reek:FeatureEnvy
|
23
22
|
def call template, attributes
|
24
|
-
return attributes
|
25
|
-
return attributes unless template.match? pattern
|
23
|
+
return attributes unless String(template).match? pattern
|
26
24
|
|
27
25
|
keys = scan template
|
28
26
|
attributes.slice(*keys).merge!(attributes.except(*keys))
|
data/lib/cogger/hub.rb
CHANGED
@@ -6,7 +6,6 @@ require "refinements/hash"
|
|
6
6
|
|
7
7
|
module Cogger
|
8
8
|
# Loads configuration and simultaneously sends messages to multiple streams.
|
9
|
-
# :reek:TooManyInstanceVariables
|
10
9
|
# :reek:TooManyMethods
|
11
10
|
class Hub
|
12
11
|
extend Forwardable
|
@@ -40,7 +39,6 @@ module Cogger
|
|
40
39
|
@configuration = model[**find_formatter(attributes)]
|
41
40
|
@primary = configuration.to_logger
|
42
41
|
@streams = [@primary]
|
43
|
-
@mutex = Mutex.new
|
44
42
|
end
|
45
43
|
|
46
44
|
def add_stream **attributes
|
@@ -80,7 +78,7 @@ module Cogger
|
|
80
78
|
|
81
79
|
private
|
82
80
|
|
83
|
-
attr_reader :registry, :configuration, :primary, :streams
|
81
|
+
attr_reader :registry, :configuration, :primary, :streams
|
84
82
|
|
85
83
|
# :reek:FeatureEnvy
|
86
84
|
def find_formatter attributes
|
@@ -110,7 +108,7 @@ module Cogger
|
|
110
108
|
&
|
111
109
|
)
|
112
110
|
|
113
|
-
mutex.synchronize { streams.each { |logger| logger.public_send level, entry } }
|
111
|
+
configuration.mutex.synchronize { streams.each { |logger| logger.public_send level, entry } }
|
114
112
|
true
|
115
113
|
end
|
116
114
|
# rubocop:enable Metrics/MethodLength
|
data/lib/cogger/registry.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "refinements/hash"
|
3
4
|
require "tone"
|
4
5
|
|
5
6
|
module Cogger
|
6
7
|
# Provides a global regsitry for global configuration.
|
7
8
|
module Registry
|
9
|
+
using Refinements::Hash
|
10
|
+
|
8
11
|
def self.extended descendant
|
9
12
|
descendant.add_alias(:debug, :white)
|
10
13
|
.add_alias(:info, :green)
|
@@ -12,12 +15,14 @@ module Cogger
|
|
12
15
|
.add_alias(:error, :red)
|
13
16
|
.add_alias(:fatal, :bold, :white, :on_red)
|
14
17
|
.add_alias(:any, :dim, :bright_white)
|
15
|
-
.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
.add_emojis(
|
19
|
+
debug: "π",
|
20
|
+
info: "π’",
|
21
|
+
warn: "β οΈ",
|
22
|
+
error: "π",
|
23
|
+
fatal: "π₯",
|
24
|
+
any: "β«οΈ"
|
25
|
+
)
|
21
26
|
.add_formatter(:color, Cogger::Formatters::Color)
|
22
27
|
.add_formatter(
|
23
28
|
:detail,
|
@@ -42,10 +47,18 @@ module Cogger
|
|
42
47
|
def aliases = color.aliases
|
43
48
|
|
44
49
|
def add_emoji key, value
|
50
|
+
warn "`#{self.class}##{__method__}` is deprecated, use `#add_emojis` instead.",
|
51
|
+
category: :deprecated
|
52
|
+
|
45
53
|
emojis[key.to_sym] = value
|
46
54
|
self
|
47
55
|
end
|
48
56
|
|
57
|
+
def add_emojis(**attributes)
|
58
|
+
emojis.merge! attributes.symbolize_keys!
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
49
62
|
def get_emoji key
|
50
63
|
emojis.fetch(key.to_sym) { fail KeyError, "Unregistered emoji: #{key}." }
|
51
64
|
end
|
@@ -53,10 +66,18 @@ module Cogger
|
|
53
66
|
def emojis = @emojis ||= {}
|
54
67
|
|
55
68
|
def add_filter key
|
69
|
+
warn "`#{self.class}##{__method__}` is deprecated, use `#add_filters` instead.",
|
70
|
+
category: :deprecated
|
71
|
+
|
56
72
|
filters.add key.to_sym
|
57
73
|
self
|
58
74
|
end
|
59
75
|
|
76
|
+
def add_filters(*keys)
|
77
|
+
filters.merge(keys.map(&:to_sym))
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
60
81
|
def filters = @filters ||= Set.new
|
61
82
|
|
62
83
|
def add_formatter key, formatter, template = nil
|
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: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -69,14 +69,14 @@ dependencies:
|
|
69
69
|
requirements:
|
70
70
|
- - "~>"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '13.
|
72
|
+
version: '13.5'
|
73
73
|
type: :runtime
|
74
74
|
prerelease: false
|
75
75
|
version_requirements: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '13.
|
79
|
+
version: '13.5'
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: tone
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: 3.
|
178
|
+
rubygems_version: 3.7.1
|
179
179
|
specification_version: 4
|
180
180
|
summary: A customizable and feature rich logger.
|
181
181
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|