dvla-herodotus 2.3.1 → 2.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 +10 -0
- data/README.md +69 -0
- data/lib/dvla/herodotus/config.rb +23 -0
- data/lib/dvla/herodotus/herodotus_logger.rb +13 -3
- data/lib/dvla/herodotus/semantic_colours.rb +37 -0
- data/lib/dvla/herodotus/string.rb +23 -0
- data/lib/dvla/herodotus/version.rb +1 -1
- data/lib/dvla/herodotus.rb +21 -7
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08b398fb7ae7d18a9be9653b39e992d0ecd22b772fbeade85b9e139143b98576'
|
|
4
|
+
data.tar.gz: 93bd49a4c0f34d18f881dc74455ec190c35e44f15ab35df8e4085d38f2be1f08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a372da131b6e460d416be4e4787b3e9f4c3845cb7a40b41ccecf23d0908d19abbded195767df4b5d016639a7fda8ed241645df4edb0582eed2f75b7ae4b541f6
|
|
7
|
+
data.tar.gz: b27ed768a5f2bb9a69824ed1b5166839d84cd2b7eb96564c29bc854f40698edc6420dfaa4ec8f5a481d57164821e8e85fb50eeb75fea4438f0dbd168fdaf0dc7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [2.4.0] - 2026-07-29
|
|
5
|
+
- Added semantic logging methods: `.config`, `.step`, `.success`, `.warning`, `.data`
|
|
6
|
+
- Semantic methods apply standard colours based on message type for consistent logging
|
|
7
|
+
- Semantic colours can be configured in the main `DVLA::Herodotus.configure` block alongside logger options
|
|
8
|
+
- Added `DVLA::Herodotus.reset_configuration!` to reset both logger options and semantic colours
|
|
9
|
+
- `DVLA::Herodotus::SemanticColours.configure` and `.reset!` still available for standalone colour configuration
|
|
10
|
+
|
|
11
|
+
## [2.3.2] - 2025-12-23
|
|
12
|
+
- Add 'spawn_child_logger' method to allow other processes to inherit the current logger's configuration
|
|
13
|
+
|
|
4
14
|
## [2.3.1] - 2025-11-21
|
|
5
15
|
- Fixed issue with output_path in create_logger, will now make a directory if it did not exist
|
|
6
16
|
|
data/README.md
CHANGED
|
@@ -102,6 +102,22 @@ You can call `new_scenario` with the identifier just before each scenario to cre
|
|
|
102
102
|
logger.new_scenario('Scenario Id')
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
+
### spawn_child_logger method
|
|
106
|
+
You can call `spawn_child_logger` with a new system_name which will retain the current logger's config.
|
|
107
|
+
This enables you to pass loggers to other tools and maintain the same colourisation and output_path.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
config = DVLA::Herodotus.config do |configuration|
|
|
111
|
+
configuration.display_pid = false
|
|
112
|
+
configuration.main = true
|
|
113
|
+
configuration.prefix_colour = {
|
|
114
|
+
overall: %w[blue bold],
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
LOG = DVLA::Herodotus.logger('<system-name>', config:, output_path: -> { "log.txt" })
|
|
118
|
+
NewTool.new(logger: LOG.spawn_child_logger(system_name: 'new gem'))
|
|
119
|
+
```
|
|
120
|
+
|
|
105
121
|
---
|
|
106
122
|
### Strings
|
|
107
123
|
|
|
@@ -135,6 +151,59 @@ You can stack multiple method calls to add additional styling and use string int
|
|
|
135
151
|
|
|
136
152
|
---
|
|
137
153
|
|
|
154
|
+
### Semantic Logging Methods
|
|
155
|
+
|
|
156
|
+
Herodotus provides semantic methods that associate message types with standard colours. This promotes consistent colour usage across teams and makes logs easier to read.
|
|
157
|
+
|
|
158
|
+
```ruby
|
|
159
|
+
LOG.info { "Environment: #{env}".config } # brown - configuration/environment
|
|
160
|
+
LOG.info { "Checking image status".step } # magenta - step execution/progress
|
|
161
|
+
LOG.info { "Application completed".success } # green - successful operations
|
|
162
|
+
LOG.info { "Retrying request".warning } # yellow - warnings/non-fatal issues
|
|
163
|
+
LOG.info { "Response: #{payload}".data } # blue - data values/payloads
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Default Colours
|
|
167
|
+
|
|
168
|
+
| Method | Default Colour | Usage |
|
|
169
|
+
|-----------|----------------|-------------------------------------|
|
|
170
|
+
| `.config` | brown | Configuration, environment settings |
|
|
171
|
+
| `.step` | magenta | Method calls, checking, polling |
|
|
172
|
+
| `.success`| green | Successful operations, completions |
|
|
173
|
+
| `.warning`| yellow | Warnings, non-fatal issues |
|
|
174
|
+
| `.data` | blue | Data values, responses, payloads |
|
|
175
|
+
|
|
176
|
+
#### Custom Colour Configuration
|
|
177
|
+
|
|
178
|
+
You can configure semantic colours alongside other logger options in a single configure block:
|
|
179
|
+
|
|
180
|
+
```ruby
|
|
181
|
+
DVLA::Herodotus.configure do |c|
|
|
182
|
+
c.display_pid = true
|
|
183
|
+
c.prefix_colour = { overall: :blue }
|
|
184
|
+
c.config = :cyan
|
|
185
|
+
c.step = :blue
|
|
186
|
+
c.success = :bright_green
|
|
187
|
+
c.warning = :red
|
|
188
|
+
c.data = :magenta
|
|
189
|
+
end
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
To reset all configuration to defaults:
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
DVLA::Herodotus.reset_configuration!
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Semantic methods can be chained with other styles:
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
LOG.info { "COMPLETED".success.bold }
|
|
202
|
+
LOG.info { "ERROR: #{msg}".warning.bg_red }
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
138
207
|
## Development
|
|
139
208
|
|
|
140
209
|
Herodotus is very lightweight. Currently, all code to generate a new logger can be found in `herodotus.rb` and the code for the logger is in `herodotus_logger.rb` so that is the best place to start with any modifications
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module DVLA
|
|
2
|
+
module Herodotus
|
|
3
|
+
class Config
|
|
4
|
+
LOGGER_ATTRIBUTES = %i[display_pid main prefix_colour].freeze
|
|
5
|
+
|
|
6
|
+
attr_accessor(*LOGGER_ATTRIBUTES)
|
|
7
|
+
|
|
8
|
+
SemanticColours::DEFAULT_COLOURS.keys.each do |semantic_type|
|
|
9
|
+
define_method(semantic_type) do
|
|
10
|
+
SemanticColours.send(semantic_type)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
define_method("#{semantic_type}=") do |colour|
|
|
14
|
+
SemanticColours.send("#{semantic_type}=", colour)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reset_colours!
|
|
19
|
+
SemanticColours.reset!
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -13,9 +13,9 @@ module DVLA
|
|
|
13
13
|
super(*args, **kwargs)
|
|
14
14
|
|
|
15
15
|
@system_name = system_name
|
|
16
|
-
@main = config
|
|
17
|
-
@display_pid = config
|
|
18
|
-
@prefix_colour = config
|
|
16
|
+
@main = config.main
|
|
17
|
+
@display_pid = config.display_pid
|
|
18
|
+
@prefix_colour = config.prefix_colour || {}
|
|
19
19
|
validate_colour_config if @prefix_colour.any?
|
|
20
20
|
@correlation_id = SecureRandom.uuid[0, 8]
|
|
21
21
|
set_formatter
|
|
@@ -58,6 +58,16 @@ module DVLA
|
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
# Creates a new logger with a different system name but inherits config and output path
|
|
62
|
+
def spawn_child_logger(system_name:)
|
|
63
|
+
config = DVLA::Herodotus.config do |c|
|
|
64
|
+
c.display_pid = @display_pid
|
|
65
|
+
c.main = false
|
|
66
|
+
c.prefix_colour = @prefix_colour
|
|
67
|
+
end
|
|
68
|
+
HerodotusLogger.new(system_name, @logdev.dev, config: config)
|
|
69
|
+
end
|
|
70
|
+
|
|
61
71
|
%i[debug info warn error fatal].each do |log_level|
|
|
62
72
|
define_method log_level do |progname = nil, &block|
|
|
63
73
|
set_proc_writer_scenario
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module DVLA
|
|
2
|
+
module Herodotus
|
|
3
|
+
module SemanticColours
|
|
4
|
+
DEFAULT_COLOURS = {
|
|
5
|
+
config: :brown,
|
|
6
|
+
step: :magenta,
|
|
7
|
+
success: :green,
|
|
8
|
+
warning: :yellow,
|
|
9
|
+
data: :blue
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def colours
|
|
14
|
+
@colours ||= DEFAULT_COLOURS.dup
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def configure
|
|
18
|
+
yield(self) if block_given?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def reset!
|
|
22
|
+
@colours = DEFAULT_COLOURS.dup
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
DEFAULT_COLOURS.keys.each do |semantic_type|
|
|
26
|
+
define_method(semantic_type) do
|
|
27
|
+
colours[semantic_type]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
define_method("#{semantic_type}=") do |colour|
|
|
31
|
+
colours[semantic_type] = colour
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative 'semantic_colours'
|
|
2
|
+
|
|
1
3
|
class String
|
|
2
4
|
def colourise(code, reset_code = 39)
|
|
3
5
|
# Making sure we align the correct reset codes
|
|
@@ -88,4 +90,25 @@ class String
|
|
|
88
90
|
alias grey gray
|
|
89
91
|
alias reverse_color reverse_colour
|
|
90
92
|
alias strip_color strip_colour
|
|
93
|
+
|
|
94
|
+
# Semantic logging methods - apply colours based on message type
|
|
95
|
+
def config
|
|
96
|
+
send(DVLA::Herodotus::SemanticColours.config)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def step
|
|
100
|
+
send(DVLA::Herodotus::SemanticColours.step)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def success
|
|
104
|
+
send(DVLA::Herodotus::SemanticColours.success)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def warning
|
|
108
|
+
send(DVLA::Herodotus::SemanticColours.warning)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def data
|
|
112
|
+
send(DVLA::Herodotus::SemanticColours.data)
|
|
113
|
+
end
|
|
91
114
|
end
|
data/lib/dvla/herodotus.rb
CHANGED
|
@@ -3,23 +3,37 @@ require 'fileutils'
|
|
|
3
3
|
require_relative 'herodotus/herodotus_logger'
|
|
4
4
|
require_relative 'herodotus/multi_writer'
|
|
5
5
|
require_relative 'herodotus/proc_writer'
|
|
6
|
+
require_relative 'herodotus/semantic_colours'
|
|
7
|
+
require_relative 'herodotus/config'
|
|
6
8
|
require_relative 'herodotus/string'
|
|
7
9
|
|
|
8
10
|
module DVLA
|
|
9
11
|
module Herodotus
|
|
10
12
|
class << self
|
|
11
13
|
attr_accessor :main_logger
|
|
12
|
-
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
def configuration
|
|
16
|
+
@configuration ||= Config.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def configure
|
|
20
|
+
yield(configuration) if block_given?
|
|
21
|
+
configuration
|
|
22
|
+
end
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
def config
|
|
25
|
+
c = Config.new
|
|
26
|
+
yield(c) if block_given?
|
|
27
|
+
c
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def reset_configuration!
|
|
31
|
+
@configuration = Config.new
|
|
32
|
+
SemanticColours.reset!
|
|
33
|
+
end
|
|
20
34
|
end
|
|
21
35
|
|
|
22
|
-
def self.logger(system_name, config: self.
|
|
36
|
+
def self.logger(system_name, config: self.configuration, output_path: nil)
|
|
23
37
|
create_logger(system_name, config, output_path)
|
|
24
38
|
end
|
|
25
39
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dvla-herodotus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Driver and Vehicle Licensing Agency (DVLA)
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-08-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: dvla-lint
|
|
@@ -59,9 +59,11 @@ files:
|
|
|
59
59
|
- bin/console
|
|
60
60
|
- dvla-herodotus.gemspec
|
|
61
61
|
- lib/dvla/herodotus.rb
|
|
62
|
+
- lib/dvla/herodotus/config.rb
|
|
62
63
|
- lib/dvla/herodotus/herodotus_logger.rb
|
|
63
64
|
- lib/dvla/herodotus/multi_writer.rb
|
|
64
65
|
- lib/dvla/herodotus/proc_writer.rb
|
|
66
|
+
- lib/dvla/herodotus/semantic_colours.rb
|
|
65
67
|
- lib/dvla/herodotus/string.rb
|
|
66
68
|
- lib/dvla/herodotus/version.rb
|
|
67
69
|
homepage: https://github.com/dvla/herodotus
|