hubbado-log 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
- data/ChangeLog.md +52 -0
- data/README.md +61 -0
- data/hubbado-log.gemspec +2 -1
- data/lib/hubbado/log/controls/log_handler.rb +2 -2
- data/lib/hubbado/log/controls/logger.rb +16 -0
- data/lib/hubbado/log/controls.rb +1 -0
- data/lib/hubbado/log/logger/substitute.rb +50 -0
- data/lib/hubbado/log.rb +1 -0
- metadata +17 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c548a1c52601a45c8ffb53337dcfe28805e63cbe868d90692f5bff54b8fc4f82
|
|
4
|
+
data.tar.gz: da676bfa5ff5ee43efa7660412ea53da1c307e4fdadf8570cc6bd1251178c60b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7a795d9bc507c468e12232058d413c916f8f6e155f68793e6305314c50c7bf8e5528a690280c9b9b265824cf6e8cb6e428741aaa4df0abe6550dcf9cc0fb636
|
|
7
|
+
data.tar.gz: 308912bee3a3af9ca487628ba15cadbe74f33fdce80ee329585229a34b7bae25f832167c2d7250189fa50b6d30c0ad4d7a3e07fdb78e8e207f0032f8f31d44b0
|
data/ChangeLog.md
CHANGED
|
@@ -4,6 +4,58 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
# [1.4.0 - 2026-08-16]
|
|
8
|
+
## Added
|
|
9
|
+
- A substitute for a logger. `Controls::Logger.example` returns one, and a spec
|
|
10
|
+
assigns it where a class's logger goes:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
instance.logger = Hubbado::Log::Controls::Logger.example
|
|
14
|
+
|
|
15
|
+
instance.()
|
|
16
|
+
|
|
17
|
+
assert instance.logger.logged?(:error)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
It records what it was told rather than writing, so no handler is involved and
|
|
21
|
+
neither the level nor the tag list decides what a spec can read back.
|
|
22
|
+
|
|
23
|
+
Three questions, each taking an optional severity, and each answering in the
|
|
24
|
+
terms its name promises:
|
|
25
|
+
|
|
26
|
+
| Call | Answers |
|
|
27
|
+
|---|---|
|
|
28
|
+
| `logged?(:warn)` | whether anything was written at that severity |
|
|
29
|
+
| `messages(:warn)` | what it said — the message strings |
|
|
30
|
+
| `logged(:warn)` | everything about what it said — `severity`, `message`, `data` |
|
|
31
|
+
|
|
32
|
+
`messages` and `logged?` are both derived from `logged`, so the three cannot
|
|
33
|
+
disagree about what counts as written at a severity.
|
|
34
|
+
|
|
35
|
+
A severity reaches a logger two ways — as the generated method, or as `#log`'s
|
|
36
|
+
first argument — and both answer the same question, compared as symbols.
|
|
37
|
+
|
|
38
|
+
- `evt-subst_attr` as a runtime dependency. The substitute is a mimic of `Logger`
|
|
39
|
+
extended with `Logger::Substitute`, so it answers `is_a?(Logger)` for a class
|
|
40
|
+
that checks, and gains any method `Logger` gains.
|
|
41
|
+
|
|
42
|
+
## Deprecated
|
|
43
|
+
- `Controls::LogHandler` as the way a consumer reads back what a class logged.
|
|
44
|
+
It builds a real `Logger` and then passes `level: :trace` and `tags: Tags::ALL`
|
|
45
|
+
to switch off the filtering it just built — which is a substitute, reached the
|
|
46
|
+
long way round. Use `Controls::Logger.example`. The handler control stays for
|
|
47
|
+
what it is good at: specs where a handler receiving, or not receiving, a
|
|
48
|
+
message is the subject, as `'A message the filter left out'` is.
|
|
49
|
+
|
|
50
|
+
## Changed
|
|
51
|
+
- `Controls::LogHandler` names `Log::Logger` where it said `Logger`. With
|
|
52
|
+
`Controls::Logger` defined, a bare `Logger` inside `Controls` resolves to the
|
|
53
|
+
control rather than to the class.
|
|
54
|
+
|
|
55
|
+
## Compatibility
|
|
56
|
+
Nothing that exists breaks. `Controls::LogHandler` keeps `.attach`, `.logger`,
|
|
57
|
+
`messages`, `logged?`, `reset` and the attributes, unchanged.
|
|
58
|
+
|
|
7
59
|
# [1.3.0 - 2026-08-15]
|
|
8
60
|
## Added
|
|
9
61
|
- Tags, a second filtering axis beside the level. A message names its concern
|
data/README.md
CHANGED
|
@@ -111,6 +111,67 @@ knowing before adopting tags:
|
|
|
111
111
|
list decides for both, and an application whose messages are all untagged goes silent unless the
|
|
112
112
|
list contains `_untagged`.
|
|
113
113
|
|
|
114
|
+
## Reading back what a class logged
|
|
115
|
+
|
|
116
|
+
A spec assigns a substitute where the class's logger goes, and then asks what the class said:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
require 'hubbado/log/controls'
|
|
120
|
+
|
|
121
|
+
instance.logger = Hubbado::Log::Controls::Logger.example
|
|
122
|
+
|
|
123
|
+
instance.()
|
|
124
|
+
|
|
125
|
+
assert instance.logger.logged?(:error)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
For a class handed a logger rather than carrying one — the shape a CLI usually takes — it is the
|
|
129
|
+
same object, passed in:
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
logger = Hubbado::Log::Controls::Logger.example
|
|
133
|
+
|
|
134
|
+
CLI.run(argv, logger: logger)
|
|
135
|
+
|
|
136
|
+
assert logger.logged?(:error)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
It records what it was told rather than writing, so no handler is involved and neither the
|
|
140
|
+
configured level nor `LOG_TAGS` decides what can be read back.
|
|
141
|
+
|
|
142
|
+
Three questions, each taking an optional severity:
|
|
143
|
+
|
|
144
|
+
| Call | Answers |
|
|
145
|
+
|---|---|
|
|
146
|
+
| `logged?` / `logged?(:warn)` | whether anything was written, at all or at that severity |
|
|
147
|
+
| `messages` / `messages(:warn)` | what it said — the message strings, in order |
|
|
148
|
+
| `logged` / `logged(:warn)` | everything about what it said |
|
|
149
|
+
|
|
150
|
+
`logged` answers with entries carrying `severity`, `message` and `data`, for the assertion that
|
|
151
|
+
needs more than the text:
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
assert logger.logged(:error).first.data.equal?(exception)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`messages` and `logged?` are both derived from `logged`, so the three cannot disagree about what
|
|
158
|
+
counts as written at a severity.
|
|
159
|
+
|
|
160
|
+
A severity reaches a logger two ways — `logger.warn('…')` names it as the method,
|
|
161
|
+
`logger.log(:warn, '…')` as an argument — and both answer the same question, compared as symbols.
|
|
162
|
+
|
|
163
|
+
The substitute is a mimic of `Logger`, so it answers `is_a?(Hubbado::Log::Logger)` for a class
|
|
164
|
+
that checks, and gains any method `Logger` gains.
|
|
165
|
+
|
|
166
|
+
Prefer `logged?` to reaching into `messages` where it will do. That a failure was reported is
|
|
167
|
+
usually the contract; the wording of the line usually is not.
|
|
168
|
+
|
|
169
|
+
### Testing a handler
|
|
170
|
+
|
|
171
|
+
`Controls::LogHandler` is for specs where a handler receiving — or not receiving — a message is
|
|
172
|
+
itself the subject, which in practice means this gem's own tests of level and tag filtering. A
|
|
173
|
+
consumer asserting that its class logged something wants the substitute above.
|
|
174
|
+
|
|
114
175
|
## Development
|
|
115
176
|
|
|
116
177
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/hubbado-log.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "hubbado-log"
|
|
3
|
-
s.version = "1.
|
|
3
|
+
s.version = "1.4.0"
|
|
4
4
|
s.summary = "Lightweight pluggable logging system"
|
|
5
5
|
|
|
6
6
|
s.authors = ["Hubbado Devs"]
|
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.required_ruby_version = '>= 3.2'
|
|
26
26
|
|
|
27
27
|
s.add_runtime_dependency 'evt-dependency'
|
|
28
|
+
s.add_runtime_dependency 'evt-subst_attr'
|
|
28
29
|
|
|
29
30
|
s.add_development_dependency "debug"
|
|
30
31
|
s.add_development_dependency "hubbado-style"
|
|
@@ -20,7 +20,7 @@ module Hubbado
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
new.tap do |handler|
|
|
23
|
-
instance.logger = Logger.new(logger.subject, [handler], level: level, tags: tags)
|
|
23
|
+
instance.logger = Log::Logger.new(logger.subject, [handler], level: level, tags: tags)
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ module Hubbado
|
|
|
28
28
|
def self.logger(subject = Subject.example, level: :trace, tags: Tags::ALL)
|
|
29
29
|
handler = new
|
|
30
30
|
|
|
31
|
-
[handler, Logger.new(subject, [handler], level: level, tags: tags)]
|
|
31
|
+
[handler, Log::Logger.new(subject, [handler], level: level, tags: tags)]
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def log(subject, severity, message, data = nil, stacktrace = nil)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'subst_attr'
|
|
2
|
+
|
|
3
|
+
module Hubbado
|
|
4
|
+
class Log
|
|
5
|
+
module Controls
|
|
6
|
+
module Logger
|
|
7
|
+
# A logger a spec assigns in place of a class's own, and then asks what the class said.
|
|
8
|
+
# Named here because the substitute is reached by building a mimic of Log::Logger, which
|
|
9
|
+
# is machinery a spec should not have to name.
|
|
10
|
+
def self.example
|
|
11
|
+
SubstAttr::Substitute.build(Log::Logger)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/hubbado/log/controls.rb
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Hubbado
|
|
2
|
+
class Log
|
|
3
|
+
class Logger
|
|
4
|
+
# What a logger was told rather than what it wrote. Extended onto a mimic of Logger, so a
|
|
5
|
+
# class under test is handed something that answers as a logger and keeps what it was given.
|
|
6
|
+
module Substitute
|
|
7
|
+
Entry = Data.define(:severity, :message, :data)
|
|
8
|
+
|
|
9
|
+
# Everything about what a class said, in order. Named with a severity, only what it said
|
|
10
|
+
# at that one.
|
|
11
|
+
#
|
|
12
|
+
# A severity reaches a logger two ways: as the method, from the generated severity
|
|
13
|
+
# methods, or as #log's first argument. Both are compared as symbols, because #log takes
|
|
14
|
+
# a String as readily and passes on what it was given.
|
|
15
|
+
def logged(severity = nil)
|
|
16
|
+
entries = invocations.map { |invocation| entry(invocation) }
|
|
17
|
+
|
|
18
|
+
return entries if severity.nil?
|
|
19
|
+
|
|
20
|
+
entries.select { |entry| entry.severity == severity.to_s.to_sym }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# What a class said, where #logged is everything about it.
|
|
24
|
+
def messages(severity = nil) = logged(severity).map(&:message)
|
|
25
|
+
|
|
26
|
+
# Whether, where #logged and #messages ask what. Without a severity, whether anything was
|
|
27
|
+
# written at all.
|
|
28
|
+
def logged?(severity = nil) = !logged(severity).empty?
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def entry(invocation)
|
|
33
|
+
arguments = invocation.arguments
|
|
34
|
+
|
|
35
|
+
Entry.new(
|
|
36
|
+
severity: severity(invocation).to_s.to_sym,
|
|
37
|
+
message: arguments[:msg],
|
|
38
|
+
data: arguments[:data]
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def severity(invocation)
|
|
43
|
+
return invocation.arguments.fetch(:severity) if invocation.method_name == :log
|
|
44
|
+
|
|
45
|
+
invocation.method_name
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/hubbado/log.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hubbado-log
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hubbado Devs
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: evt-subst_attr
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: debug
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -81,11 +95,13 @@ files:
|
|
|
81
95
|
- lib/hubbado/log/controls/data.rb
|
|
82
96
|
- lib/hubbado/log/controls/exception.rb
|
|
83
97
|
- lib/hubbado/log/controls/log_handler.rb
|
|
98
|
+
- lib/hubbado/log/controls/logger.rb
|
|
84
99
|
- lib/hubbado/log/controls/message.rb
|
|
85
100
|
- lib/hubbado/log/controls/subject.rb
|
|
86
101
|
- lib/hubbado/log/log.rb
|
|
87
102
|
- lib/hubbado/log/log_handler.rb
|
|
88
103
|
- lib/hubbado/log/logger.rb
|
|
104
|
+
- lib/hubbado/log/logger/substitute.rb
|
|
89
105
|
- lib/hubbado/log/tags.rb
|
|
90
106
|
homepage: https://www.github.com/hubbado/hubbado-log
|
|
91
107
|
licenses:
|