dry-logger 1.2.2 → 1.3.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
- data/CHANGELOG.md +16 -0
- data/README.md +6 -1
- data/dry-logger.gemspec +3 -5
- data/lib/dry/logger/filter.rb +94 -43
- data/lib/dry/logger/global.rb +1 -1
- data/lib/dry/logger/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3b306d2cacde8698d0cdb90777988dca9eb02477828d4b1b1651c301bb294d4
|
|
4
|
+
data.tar.gz: a4af60c05fc7d9845d3a6e7fcd90aa514499c8c6e1172d058c057b6fc232e98f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '096ca26a2ffc2bcf1a824ef1f08b2e4aca1eec5ce7b03df8caec590b527d7fea3b91bd8f5e5461e8037cf7bf289a7a2ab6beac841a9ef85ebc16295f7f89e43a'
|
|
7
|
+
data.tar.gz: 5169ee98f018fecce1e55310f1b41a3324bc3e500287d6f8eb7868851045a84ccc3bee8a4c75d0045a6d493e1e65bbd34f817e5abd5e92387e2f140442e51d18
|
data/CHANGELOG.md
CHANGED
|
@@ -21,6 +21,22 @@ and this project adheres to [Break Versioning](https://www.taoensso.com/break-ve
|
|
|
21
21
|
|
|
22
22
|
[Unreleased]: https://github.com/dry-rb/dry-logger/compare/v1.2.2...main
|
|
23
23
|
|
|
24
|
+
## [1.3.0] - 2026-11-18
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Support `Regexp` log filters, matched against each key and its full dotted path, ignoring case. (@timriley in #43)
|
|
29
|
+
|
|
30
|
+
### Changed
|
|
31
|
+
|
|
32
|
+
- Match log filters on substrings, ignoring case. For example, `"password"` now also filters `password_confirmation`, and `"user.token"` filters `admin.user.token_hash`. (@timriley in #43)
|
|
33
|
+
- Match string and symbol filters literally. Use a `Regexp` filter (such as `/pass/`) instead of regex syntax in a string. (@timriley in #43)
|
|
34
|
+
- Strip whitespace from the start and end of string and symbol filters. Ignore blank filters, and print a warning. (@timriley in #43)
|
|
35
|
+
- Filter hashes inside arrays, such as `{users: [{password: "secret"}]}`. (@timriley in #43)
|
|
36
|
+
- Only filter inside hashes and arrays, not hash-like `Enumerable` objects. Convert these to hashes (for example, with `#to_h`) before logging. (@timriley in #43)
|
|
37
|
+
|
|
38
|
+
[1.3.0]: https://github.com/dry-rb/dry-logger/compare/v1.2.2...v1.3.0
|
|
39
|
+
|
|
24
40
|
## [1.2.2] - 2026-03-13
|
|
25
41
|
|
|
26
42
|
### Fixed
|
data/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
<!--- This file is synced from hanakai-rb/repo-sync -->
|
|
2
2
|
|
|
3
|
-
[rubygem]: https://rubygems.org/gems/dry-logger
|
|
4
3
|
[actions]: https://github.com/dry-rb/dry-logger/actions
|
|
4
|
+
[chat]: https://discord.gg/naQApPAsZB
|
|
5
|
+
[forum]: https://discourse.hanakai.org
|
|
6
|
+
[rubygem]: https://rubygems.org/gems/dry-logger
|
|
5
7
|
|
|
6
8
|
# dry-logger [][rubygem] [][actions]
|
|
7
9
|
|
|
10
|
+
[][forum]
|
|
11
|
+
[][chat]
|
|
12
|
+
|
|
8
13
|
## Links
|
|
9
14
|
|
|
10
15
|
- [User documentation](https://dry-rb.org/gems/dry-logger)
|
data/dry-logger.gemspec
CHANGED
|
@@ -17,22 +17,20 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
spec.description = spec.summary
|
|
18
18
|
spec.homepage = "https://dry-rb.org/gems/dry-logger"
|
|
19
19
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-logger.gemspec", "lib/**/*"]
|
|
20
|
-
spec.bindir = "
|
|
21
|
-
spec.executables = []
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
|
|
22
22
|
spec.require_paths = ["lib"]
|
|
23
23
|
|
|
24
24
|
spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
|
|
25
25
|
|
|
26
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
27
26
|
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-logger/blob/main/CHANGELOG.md"
|
|
28
27
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-logger"
|
|
29
28
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-logger/issues"
|
|
30
29
|
spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
|
|
31
30
|
|
|
32
|
-
spec.required_ruby_version = ">= 3.
|
|
31
|
+
spec.required_ruby_version = ">= 3.3"
|
|
33
32
|
|
|
34
33
|
spec.add_runtime_dependency "logger"
|
|
35
|
-
|
|
36
34
|
spec.add_development_dependency "bundler"
|
|
37
35
|
spec.add_development_dependency "rake"
|
|
38
36
|
spec.add_development_dependency "rspec"
|
data/lib/dry/logger/filter.rb
CHANGED
|
@@ -2,73 +2,124 @@
|
|
|
2
2
|
|
|
3
3
|
module Dry
|
|
4
4
|
module Logger
|
|
5
|
-
#
|
|
6
|
-
#
|
|
5
|
+
# Log filtering logic.
|
|
6
|
+
#
|
|
7
|
+
# Filters match keys as follows:
|
|
8
|
+
#
|
|
9
|
+
# - A string or symbol matches any key where the text appears in the key or its full dotted
|
|
10
|
+
# path. For example, `"password"` matches `password`, `password_confirmation` and
|
|
11
|
+
# `user.new_password`, and `"user.token"` matches `user.token`, `user.token_type` and
|
|
12
|
+
# `admin.user.token`, but not a top-level `token`.
|
|
13
|
+
# - A regexp matches any key where the regexp matches the key or its full dotted path. For
|
|
14
|
+
# example, `/\Apin\z/` matches `pin` and `user.pin`, and `/\Acard\.number\z/` matches
|
|
15
|
+
# `card.number`, but not `payment.card.number`.
|
|
16
|
+
#
|
|
17
|
+
# All filters ignore case, both strings and regexps. To make a regexp filter case-sensitive, use
|
|
18
|
+
# Ruby's inline `(?-i)` modifier, such as `/(?-i)\APin\z/`.
|
|
19
|
+
#
|
|
20
|
+
# Whitespace is stripped from the start and end of string and symbol filters. Fully blank
|
|
21
|
+
# filters are ignored with a warning, since they would match every key.
|
|
22
|
+
#
|
|
23
|
+
# When a key matches and its value is a hash or an array, every value inside it is filtered.
|
|
24
|
+
#
|
|
25
|
+
# Hashes inside arrays are also filtered. Their keys use the array's key in their dotted path,
|
|
26
|
+
# with no index. For example, `"users.password"` matches `{users: [{password: "secret"}]}`.
|
|
7
27
|
#
|
|
8
28
|
# @api private
|
|
9
29
|
class Filter
|
|
10
|
-
|
|
30
|
+
FILTERED = "[FILTERED]"
|
|
31
|
+
private_constant :FILTERED
|
|
32
|
+
|
|
33
|
+
PATH_SEPARATOR = "."
|
|
34
|
+
private_constant :PATH_SEPARATOR
|
|
35
|
+
|
|
36
|
+
private attr_reader :matcher
|
|
37
|
+
|
|
11
38
|
def initialize(filters = [])
|
|
12
|
-
@
|
|
39
|
+
@matcher = build_matcher(reject_blank_filters(strip_filters(filters)))
|
|
13
40
|
end
|
|
14
41
|
|
|
15
|
-
# @api private
|
|
16
42
|
def call(hash)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_filtered_keys(hash).each do |key|
|
|
20
|
-
*keys, last = _actual_keys(hash, key.split("."))
|
|
21
|
-
keys.inject(hash, :fetch)[last] = "[FILTERED]"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
hash
|
|
43
|
+
_filter_hash(hash)
|
|
25
44
|
end
|
|
26
45
|
|
|
27
46
|
private
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_key_paths(hash).select { |key|
|
|
33
|
-
filters.any? { |filter|
|
|
34
|
-
key =~ /(\.|\A)#{filter}(\.|\z)/
|
|
35
|
-
}
|
|
36
|
-
}
|
|
48
|
+
# Strips whitespace from string filters.
|
|
49
|
+
def strip_filters(filters)
|
|
50
|
+
filters.map { |filter| filter.is_a?(Regexp) ? filter : filter.to_s.strip }
|
|
37
51
|
end
|
|
38
52
|
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
def reject_blank_filters(filters)
|
|
54
|
+
blank, present = filters.partition { |filter| filter.to_s.empty? }
|
|
55
|
+
|
|
56
|
+
unless blank.empty?
|
|
57
|
+
warn "dry-logger: ignoring blank log filter(s). Blank filters would match every key."
|
|
42
58
|
end
|
|
59
|
+
|
|
60
|
+
present
|
|
43
61
|
end
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
# Returns a regexp matching any of the filters, ignoring case. With no filters, it matches
|
|
64
|
+
# nothing.
|
|
65
|
+
#
|
|
66
|
+
# Regexp filters keep their other options. Inline modifiers such as `(?-i)` still apply, so
|
|
67
|
+
# they can opt back into case-sensitive matching.
|
|
68
|
+
def build_matcher(filters)
|
|
69
|
+
Regexp.union(
|
|
70
|
+
filters.map { |filter|
|
|
71
|
+
if filter.is_a?(Regexp)
|
|
72
|
+
Regexp.new(filter.source, filter.options | Regexp::IGNORECASE)
|
|
73
|
+
else
|
|
74
|
+
Regexp.new(Regexp.escape(filter), Regexp::IGNORECASE)
|
|
75
|
+
end
|
|
76
|
+
}
|
|
77
|
+
)
|
|
47
78
|
end
|
|
48
79
|
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
# Returns a filtered copy of the hash, leaving the original unchanged.
|
|
81
|
+
def _filter_hash(hash, parent_path = nil)
|
|
82
|
+
hash.each_with_object({}) do |(key, value), result|
|
|
83
|
+
path = parent_path ? "#{parent_path}#{PATH_SEPARATOR}#{key}" : key.to_s
|
|
51
84
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
85
|
+
result[key] =
|
|
86
|
+
if _filter?(key.to_s, path)
|
|
87
|
+
_filtered_value(value)
|
|
88
|
+
else
|
|
89
|
+
_filter_value(value, path)
|
|
90
|
+
end
|
|
56
91
|
end
|
|
57
92
|
end
|
|
58
93
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
94
|
+
def _filter_value(value, path)
|
|
95
|
+
case value
|
|
96
|
+
when Hash
|
|
97
|
+
_filter_hash(value, path)
|
|
98
|
+
when Array
|
|
99
|
+
value.map { |item| _filter_value(item, path) }
|
|
100
|
+
else
|
|
101
|
+
value
|
|
102
|
+
end
|
|
65
103
|
end
|
|
66
104
|
|
|
67
|
-
# Returns
|
|
68
|
-
def
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
105
|
+
# Returns true if any filter matches the key or its full dotted path.
|
|
106
|
+
def _filter?(key, path)
|
|
107
|
+
# Checking the key catches anchored regexps such as `/\Apin\z/` on nested keys. Checking the
|
|
108
|
+
# path catches filters that span keys, such as `"user.token"`.
|
|
109
|
+
matcher.match?(key) || matcher.match?(path)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Filters every value inside a hash or array, keeping hash keys and array lengths so the
|
|
113
|
+
# shape of the data is still visible in the logs.
|
|
114
|
+
def _filtered_value(value)
|
|
115
|
+
case value
|
|
116
|
+
when Hash
|
|
117
|
+
value.transform_values { |nested| _filtered_value(nested) }
|
|
118
|
+
when Array
|
|
119
|
+
value.map { |item| _filtered_value(item) }
|
|
120
|
+
else
|
|
121
|
+
FILTERED
|
|
122
|
+
end
|
|
72
123
|
end
|
|
73
124
|
end
|
|
74
125
|
end
|
data/lib/dry/logger/global.rb
CHANGED
|
@@ -83,7 +83,7 @@ module Dry
|
|
|
83
83
|
when nil then templates[:default]
|
|
84
84
|
else
|
|
85
85
|
raise ArgumentError,
|
|
86
|
-
|
|
86
|
+
":template option must be a Symbol or a String (`#{template_spec}` given)"
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
formatter_options = {**options, template: template}
|
data/lib/dry/logger/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dry-logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hanakai team
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
@@ -103,7 +103,6 @@ homepage: https://dry-rb.org/gems/dry-logger
|
|
|
103
103
|
licenses:
|
|
104
104
|
- MIT
|
|
105
105
|
metadata:
|
|
106
|
-
allowed_push_host: https://rubygems.org
|
|
107
106
|
changelog_uri: https://github.com/dry-rb/dry-logger/blob/main/CHANGELOG.md
|
|
108
107
|
source_code_uri: https://github.com/dry-rb/dry-logger
|
|
109
108
|
bug_tracker_uri: https://github.com/dry-rb/dry-logger/issues
|
|
@@ -115,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
115
114
|
requirements:
|
|
116
115
|
- - ">="
|
|
117
116
|
- !ruby/object:Gem::Version
|
|
118
|
-
version: '3.
|
|
117
|
+
version: '3.3'
|
|
119
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
119
|
requirements:
|
|
121
120
|
- - ">="
|