cogger 1.3.0 → 1.4.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 +55 -0
- data/cogger.gemspec +1 -1
- 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 +1 -3
- data/lib/cogger/hub.rb +2 -4
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: c31256d5e4f8446c023227a43adb18992c566a027c61f7b3356cea081662b2ed
|
4
|
+
data.tar.gz: 0ef798366fa9b799dbf24967e656ae5840d14e62953aad6c551aac462e0ff1a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242434b94151c9072d5dd0bbd5c8985a2020001ed6bd30eb406684755595bac2747c298c694a7c945f3da06a358fceb94b60a8a095c79c169ef2ab55db19411b
|
7
|
+
data.tar.gz: b3e3e7d9ee7d95b987d6c51c019f8811e0ac1aa9ddbe700997be59c51bf64b13a4903c27c985ffc83d50b7ab90a799bcb842db9aa15875cdb1f40aa8a24e88c7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -282,6 +282,26 @@ Aliases are a powerful way to customize colors via concise syntax in your templa
|
|
282
282
|
|
283
283
|
💡 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
284
|
|
285
|
+
=== Encodings
|
286
|
+
|
287
|
+
All messages use UTF-8 encoding. Any unknown character will show up as a question mark. Example:
|
288
|
+
|
289
|
+
[source,ruby]
|
290
|
+
----
|
291
|
+
logger = Cogger.new
|
292
|
+
bad = "b\xE9d".dup.force_encoding "ASCII-8BIT"
|
293
|
+
|
294
|
+
logger.info bad # "b?d"
|
295
|
+
logger.info { bad } # "b?d"
|
296
|
+
----
|
297
|
+
|
298
|
+
The underlying implementation uses the following to produce the logs shown above:
|
299
|
+
|
300
|
+
[source,ruby]
|
301
|
+
----
|
302
|
+
message.encode "UTF-8", invalid: :replace, undef: :replace, replace: "?"
|
303
|
+
----
|
304
|
+
|
285
305
|
=== Templates
|
286
306
|
|
287
307
|
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:
|
@@ -746,6 +766,41 @@ logger.info "Demo", tags: ["WEB", "PRIMARY", {service: :api, demo: true}]
|
|
746
766
|
|
747
767
|
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
768
|
|
769
|
+
A block can be used with a string or hash for content. Example:
|
770
|
+
|
771
|
+
[source,ruby]
|
772
|
+
----
|
773
|
+
logger = Cogger.new formatter: :json
|
774
|
+
|
775
|
+
logger.info { "Demo" }
|
776
|
+
# {
|
777
|
+
# "id":"console",
|
778
|
+
# "level":"INFO",
|
779
|
+
# "at":"2025-08-03T13:37:58.227-06:00",
|
780
|
+
# "message":"Demo"
|
781
|
+
# }
|
782
|
+
|
783
|
+
logger.info { {message: :demo, weight: 0.2} }
|
784
|
+
# {
|
785
|
+
# "id":"console",
|
786
|
+
# "level":"INFO",
|
787
|
+
# "at":"2025-08-03T13:39:32.438-06:00",
|
788
|
+
# "message":"demo",
|
789
|
+
# "weight":0.2
|
790
|
+
# }
|
791
|
+
|
792
|
+
logger.info(tags: %w[WEB PRIMARY]) { {message: :demo, weight: 0.2} }
|
793
|
+
# {
|
794
|
+
# "id":"console",
|
795
|
+
# "level":"INFO",
|
796
|
+
# "at":"2025-08-03T13:42:22.869-06:00",
|
797
|
+
# "message":"demo",
|
798
|
+
# "tags":["WEB",
|
799
|
+
# "PRIMARY"],
|
800
|
+
# "weight":0.2
|
801
|
+
# }
|
802
|
+
----
|
803
|
+
|
749
804
|
==== Rack
|
750
805
|
|
751
806
|
This formatter is the _Simple_ formatter with a different template and can be configured as follows:
|
data/cogger.gemspec
CHANGED
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
|
@@ -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.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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -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
|