hubbado-log 1.4.0 → 1.4.1
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 +21 -0
- data/README.md +30 -0
- data/hubbado-log.gemspec +1 -1
- data/lib/hubbado/log/configuration.rb +31 -2
- data/lib/hubbado/log/log.rb +6 -12
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99367c1895c07697aa0e83dc1e068f35cf2052d75dc6c471610b47099f27fd7f
|
|
4
|
+
data.tar.gz: 58a148cfa36ea3709a2c36fbb228f089d3b176476d27ede4a74ec26a651bdf12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a53b16af1babaa5c90125bfddec34a02c5256661004833a63b5b54066a914bf764d2c3c738d0a0d2e556d4bd9ef86d96d7e40419e7acd810f2fb7ca4fe58788
|
|
7
|
+
data.tar.gz: 6f77c77d30c8a1ef7f89b2b73c8e09585aa3f39d6dd5d9046796220f699f2926c31debd5fb5b8f514e06c7a2fb66e2b5e20be6cf7f86b95e56bba6218a2ef5e5
|
data/ChangeLog.md
CHANGED
|
@@ -4,6 +4,27 @@ 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.1 - 2026-08-16]
|
|
8
|
+
## Fixed
|
|
9
|
+
- A subclass of `Hubbado::Log` can be used as a dependency. It answered `nil`
|
|
10
|
+
from `config` and raised `undefined method 'loggers' for nil` on its first
|
|
11
|
+
line, because the configuration was held in a class-level instance variable
|
|
12
|
+
and those are not inherited.
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
module Messaging
|
|
16
|
+
class Log < Hubbado::Log; end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Handler
|
|
20
|
+
include Messaging::Log::Dependency
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The configuration is the process's now, and holds the handlers built from it,
|
|
25
|
+
so every class that writes reads the one a command configured and one
|
|
26
|
+
reconfiguration reaches all of them.
|
|
27
|
+
|
|
7
28
|
# [1.4.0 - 2026-08-16]
|
|
8
29
|
## Added
|
|
9
30
|
- A substitute for a logger. `Controls::Logger.example` returns one, and a spec
|
data/README.md
CHANGED
|
@@ -18,6 +18,36 @@ Or install it yourself as:
|
|
|
18
18
|
|
|
19
19
|
$ gem install hubbado-log
|
|
20
20
|
|
|
21
|
+
## A class's own logger
|
|
22
|
+
|
|
23
|
+
A class that includes the dependency module gets a `logger` writing under its own name:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
class MyService
|
|
27
|
+
include Hubbado::Log::Dependency
|
|
28
|
+
|
|
29
|
+
def call
|
|
30
|
+
logger.info('Did the thing')
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
A subclass carries a dependency module of its own, so a library or a component can name where
|
|
36
|
+
its classes take their logger from:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
module Messaging
|
|
40
|
+
class Log < Hubbado::Log; end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class Handler
|
|
44
|
+
include Messaging::Log::Dependency
|
|
45
|
+
end
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Either way the logger writes through the handlers the process was configured with, at the level
|
|
49
|
+
and tags it was configured for.
|
|
50
|
+
|
|
21
51
|
## Level
|
|
22
52
|
|
|
23
53
|
A message below the level reaches no handler.
|
data/hubbado-log.gemspec
CHANGED
|
@@ -5,16 +5,45 @@ module Hubbado
|
|
|
5
5
|
# for a human watching one run without it also reaching every unattended log.
|
|
6
6
|
DEFAULT_LEVEL = :info
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
attr_reader :loggers
|
|
9
9
|
attr_reader :level
|
|
10
10
|
attr_reader :tags
|
|
11
11
|
|
|
12
|
+
# The configuration is the process's rather than a class's, so a subclass of Log reads the
|
|
13
|
+
# one a command wrote and there is a single set of handlers to build from it.
|
|
14
|
+
#
|
|
15
|
+
# The one place the environment is read. A command names its level and tags here or not at
|
|
16
|
+
# all, and everything downstream is handed the value rather than the variable.
|
|
17
|
+
def self.instance
|
|
18
|
+
@instance ||= new(level: ENV[LEVEL_VARIABLE], tags: ENV[TAGS_VARIABLE])
|
|
19
|
+
end
|
|
20
|
+
|
|
12
21
|
def initialize(level: nil, tags: nil)
|
|
13
|
-
|
|
22
|
+
self.loggers = []
|
|
14
23
|
self.level = level || DEFAULT_LEVEL
|
|
15
24
|
self.tags = tags
|
|
16
25
|
end
|
|
17
26
|
|
|
27
|
+
# Whatever the block leaves behind is what the process is configured for, and the handlers
|
|
28
|
+
# are built again from it. Named here rather than left to the caller, because a block is
|
|
29
|
+
# free to mutate the list of loggers in place and never reach the writer below.
|
|
30
|
+
def change
|
|
31
|
+
yield self
|
|
32
|
+
|
|
33
|
+
@log_handlers = nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The handlers themselves, one set for the process. A handler holds what it has been told,
|
|
37
|
+
# so a second set built somewhere else would be a second place to read it back from.
|
|
38
|
+
def log_handlers
|
|
39
|
+
@log_handlers ||= loggers.map(&:new)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def loggers=(value)
|
|
43
|
+
@log_handlers = nil
|
|
44
|
+
@loggers = value
|
|
45
|
+
end
|
|
46
|
+
|
|
18
47
|
# Takes the LOG_TAGS string as readily as a list, so nothing upstream has to know the
|
|
19
48
|
# syntax in order to hand a value in.
|
|
20
49
|
def tags=(value)
|
data/lib/hubbado/log/log.rb
CHANGED
|
@@ -11,22 +11,16 @@ module Hubbado
|
|
|
11
11
|
LEVEL_VARIABLE = "LOG_LEVEL".freeze
|
|
12
12
|
TAGS_VARIABLE = "LOG_TAGS".freeze
|
|
13
13
|
|
|
14
|
-
# The one place the environment is read. A command names its level and tags here or not at
|
|
15
|
-
# all, and everything downstream is handed the value rather than the variable.
|
|
16
|
-
@config = Configuration.new(level: ENV[LEVEL_VARIABLE], tags: ENV[TAGS_VARIABLE])
|
|
17
|
-
|
|
18
14
|
class << self
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def
|
|
22
|
-
yield @config
|
|
15
|
+
# Held by the configuration itself rather than here, because a class-level instance
|
|
16
|
+
# variable is not inherited: a subclass asking this class would answer nil.
|
|
17
|
+
def config = Configuration.instance
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
def configuration(&block)
|
|
20
|
+
config.change(&block)
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
def loggers
|
|
28
|
-
@loggers ||= config.loggers.map(&:new)
|
|
29
|
-
end
|
|
23
|
+
def loggers = config.log_handlers
|
|
30
24
|
|
|
31
25
|
def logger
|
|
32
26
|
@logger = Logger.new('', loggers)
|