dvla-herodotus 2.3.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ef5bb32768faf3905e84a5aa343b4905d490dfda82fd8e350e985d10387a439
4
- data.tar.gz: bf979b603e8cb1a2cfca96bb1ff837a313e0263910eef4c08b8902920bb1a462
3
+ metadata.gz: '08b398fb7ae7d18a9be9653b39e992d0ecd22b772fbeade85b9e139143b98576'
4
+ data.tar.gz: 93bd49a4c0f34d18f881dc74455ec190c35e44f15ab35df8e4085d38f2be1f08
5
5
  SHA512:
6
- metadata.gz: 62168b57257f7d376c0ca807a61822cceeb612a8eb2744e6b29755ead02b80e934317eaa56667c267407d8131324261e69a41c6e75b0d78c1f1b3e0ef126bc67
7
- data.tar.gz: b416dfe7ca587ef5ad83b04a748b7966b3c0da1336164f7cbea36330298ed8a5acc23e00ffda7b7e05075de595fee35116d6a58a4806e88bfec89e71130d2742
6
+ metadata.gz: a372da131b6e460d416be4e4787b3e9f4c3845cb7a40b41ccecf23d0908d19abbded195767df4b5d016639a7fda8ed241645df4edb0582eed2f75b7ae4b541f6
7
+ data.tar.gz: b27ed768a5f2bb9a69824ed1b5166839d84cd2b7eb96564c29bc854f40698edc6420dfaa4ec8f5a481d57164821e8e85fb50eeb75fea4438f0dbd168fdaf0dc7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
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
+
4
11
  ## [2.3.2] - 2025-12-23
5
12
  - Add 'spawn_child_logger' method to allow other processes to inherit the current logger's configuration
6
13
 
data/README.md CHANGED
@@ -151,6 +151,59 @@ You can stack multiple method calls to add additional styling and use string int
151
151
 
152
152
  ---
153
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
+
154
207
  ## Development
155
208
 
156
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[:main]
17
- @display_pid = config[:display_pid]
18
- @prefix_colour = config[:prefix_colour] || {}
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module DVLA
2
2
  module Herodotus
3
- VERSION = '2.3.2'.freeze
3
+ VERSION = '2.4.0'.freeze
4
4
  end
5
5
  end
@@ -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
- CONFIG_ATTRIBUTES = %i[display_pid main prefix_colour].freeze
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
- def self.config
17
- config ||= Struct.new(*CONFIG_ATTRIBUTES, keyword_init: true).new
18
- yield(config) if block_given?
19
- config
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.config, output_path: nil)
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.3.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: 2026-01-22 00:00:00.000000000 Z
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