legion-logging 1.3.1 → 1.3.3

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: 54638d1c2311825640cda666c7900b1bdd091ab5d8c7a322fdf72a22f7c1ec2a
4
- data.tar.gz: 3ed84565ebc83f04d7d785b2581efadcb4e99a64138f0c1e37920ee4fb78bc94
3
+ metadata.gz: 3d376fafb0c34211ae2d198730af9c5b257301242c92f18525eb9afa04c570de
4
+ data.tar.gz: 865d58843c8bd43e9564f62dd4efebfd7b5ed5745102f5b43a6fb5e048500ee2
5
5
  SHA512:
6
- metadata.gz: 45c750d7a564b0ce713abf50e985fd3749d271c86136600738f3648921d375db75564a0809fe861fb80fb3653a92ec2e1e3120858dd019261d1b9da26de9cee4
7
- data.tar.gz: c28935a6b7992cc8db82df7b2fa75e008ee60b520a3bc82752c5d6caaaa6a407a19e0ac944d2c366b84167a9f2032bad489c3f1bec3636feef171ebffac1b1cf
6
+ metadata.gz: 912e1ec7877ef76adb3f27b07eaf6283a05decfa27d325d953caf76acb295608f67a976cc56a600853a8ecf2e0a2aa247e77f100d3a65872061b6c5033e95b89
7
+ data.tar.gz: 8503664f4b1fef55b319d026bb7ccc0d13ac6a46773d234b5d8ab7aa2d56e2af61f2b4b4ff7340702012c4db3a54515a35537c8d66c6872b3affca3697cd7de7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Legion::Logging Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [1.3.3] - 2026-03-24
4
+
5
+ ### Changed
6
+ - Reindex docs: update CLAUDE.md and README with AsyncWriter and Helper module docs
7
+
8
+ ## [1.3.2] - 2026-03-22
9
+
10
+ ### Added
11
+ - `Legion::Logging::Helper` module: injectable `log` mixin for LEX extensions
12
+ - Derives logger tags from `segments`, `lex_filename`, or class name (in priority order)
13
+ - Passes through `settings[:logger]` config when available
14
+ - Allows LEX gems to use `legion-logging` directly instead of requiring the full LegionIO framework
4
15
 
5
16
  ## [1.3.1] - 2026-03-22
6
17
 
data/CLAUDE.md CHANGED
@@ -8,7 +8,7 @@
8
8
  Ruby logging class for the LegionIO framework. Provides colorized console output via Rainbow, structured JSON logging (`format: :json`), and a consistent logging interface across all Legion gems and extensions.
9
9
 
10
10
  **GitHub**: https://github.com/LegionIO/legion-logging
11
- **Version**: 1.2.5
11
+ **Version**: 1.3.2
12
12
  **License**: Apache-2.0
13
13
 
14
14
  ## Architecture
@@ -16,9 +16,11 @@ Ruby logging class for the LegionIO framework. Provides colorized console output
16
16
  ```
17
17
  Legion::Logging (singleton module)
18
18
  ├── Methods # Log level methods: debug, info, warn, error, fatal, unknown
19
- ├── Builder # Output destination (stdout/file), log level, formatter
19
+ ├── Builder # Output destination (stdout/file), log level, formatter, async: keyword
20
+ ├── AsyncWriter # Non-blocking SizedQueue-backed writer thread; fatal calls bypass queue
20
21
  ├── Hooks # Callback registry for fatal/error/warn events (on_fatal, on_error, on_warn)
21
22
  ├── EventBuilder # Structured event payload builder (caller, exception, lex, gem metadata)
23
+ ├── Helper # Injectable log mixin for LEX extensions (derives logger tags from segments/class)
22
24
  ├── Logger # Core logger configuration and setup
23
25
  ├── MultiIO # Write to multiple destinations simultaneously
24
26
  ├── SIEMExporter # PHI-redacting SIEM export (Splunk HEC, ELK/OpenSearch)
@@ -31,13 +33,15 @@ Legion::Logging (singleton module)
31
33
 
32
34
  - **Singleton Module**: `Legion::Logging` uses `class << self` - called directly: `Legion::Logging.info("msg")`
33
35
  - **Rainbow Colorization**: Console output uses Rainbow gem for colored terminal output
34
- - **Setup Method**: `Legion::Logging.setup(log_file:, level:)` configures output destination and level
36
+ - **Setup Method**: `Legion::Logging.setup(log_file:, level:, async: true)` configures output destination, level, and async mode
37
+ - **Async by Default**: `setup` enables async logging — calls return immediately. Fatal calls always bypass the queue. `stop_async_writer` flushes and stops on shutdown. Buffer size configurable via `Legion::Settings.dig(:logging, :async, :buffer_size)` (default 10,000). Back-pressure: callers block when buffer is full.
35
38
  - **Structured JSON**: `format: :json` in settings outputs machine-parseable JSON log lines
36
39
  - **Shared Interface**: Same method signature (`info`, `warn`, `error`, etc.) across all Legion components
37
40
  - **MultiIO**: Splits writes to stdout and a log file simultaneously (used by Builder when `log_file` is set)
38
41
  - **SIEMExporter**: PHI redaction (SSN, phone, MRN, DOB patterns), `export_to_splunk` (HEC), `format_for_elk`
39
- - **Hook Callbacks**: `on_fatal`, `on_error`, `on_warn` register procs called after each log at those levels. Hooks are gated by `enable_hooks!`/`disable_hooks!`. Hook failures are silently rescued — never impact the logger.
42
+ - **Hook Callbacks**: `on_fatal`, `on_error`, `on_warn` register procs called after each log at those levels. Hooks are gated by `enable_hooks!`/`disable_hooks!`. Hook failures are silently rescued — never impact the logger. Hooks fire on the async writer thread; event context captured on caller thread.
40
43
  - **EventBuilder**: Builds structured event hashes from log context (caller location, exception info, lex identity, gem metadata). All from in-memory data, zero IO.
44
+ - **Helper mixin**: `Legion::Logging::Helper` is injectable into LEX extensions. Derives logger tags from `segments`, `lex_filename`, or class name. Passes through `settings[:logger]` config when available.
41
45
 
42
46
  ## Dependencies
43
47
 
@@ -51,7 +55,9 @@ Legion::Logging (singleton module)
51
55
  |------|---------|
52
56
  | `lib/legion/logging.rb` | Module entry point |
53
57
  | `lib/legion/logging/methods.rb` | Log level methods |
54
- | `lib/legion/logging/builder.rb` | Output config and formatter |
58
+ | `lib/legion/logging/builder.rb` | Output config and formatter (async: keyword) |
59
+ | `lib/legion/logging/async_writer.rb` | Non-blocking SizedQueue-backed writer thread with back-pressure |
60
+ | `lib/legion/logging/helper.rb` | Injectable log mixin for LEX extensions |
55
61
  | `lib/legion/logging/logger.rb` | Core logger setup |
56
62
  | `lib/legion/logging/multi_io.rb` | Multi-output IO (write to multiple destinations simultaneously) |
57
63
  | `lib/legion/logging/siem_exporter.rb` | PHI-redacting SIEM export helpers (Splunk HEC, ELK format) |
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Logging module for the [LegionIO](https://github.com/LegionIO/LegionIO) framework. Provides colorized console output via Rainbow, structured JSON logging, multi-output IO, and a consistent logging interface across all Legion gems and extensions.
4
4
 
5
- **Version**: 1.3.0
5
+ **Version**: 1.3.2
6
6
 
7
7
  ## Installation
8
8
 
@@ -79,6 +79,21 @@ Legion::Logging::SIEMExporter.format_for_elk(event, index: 'legion')
79
79
 
80
80
  PHI patterns redacted: SSN (`###-##-####`), phone (`###-###-####`), MRN (`XX#######`), DOB (`##/##/####`).
81
81
 
82
+ ### Helper Mixin
83
+
84
+ `Legion::Logging::Helper` is an injectable mixin for LEX extensions. It derives logger tags from `segments`, `lex_filename`, or class name automatically, and passes through `settings[:logger]` config when available. Allows LEX gems to use `legion-logging` directly without requiring the full LegionIO framework.
85
+
86
+ ```ruby
87
+ class MyRunner
88
+ include Legion::Logging::Helper
89
+
90
+ def run
91
+ log.info("starting")
92
+ log.debug("details")
93
+ end
94
+ end
95
+ ```
96
+
82
97
  ## Requirements
83
98
 
84
99
  - Ruby >= 3.4
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Logging
5
+ module Helper
6
+ def log
7
+ return @log unless @log.nil?
8
+
9
+ logger_hash = if respond_to?(:segments)
10
+ { lex_segments: Array(segments) }
11
+ else
12
+ { lex: derive_log_tag }
13
+ end
14
+
15
+ if respond_to?(:settings) && settings.is_a?(Hash) && settings.key?(:logger)
16
+ ls = settings[:logger]
17
+ logger_hash[:level] = ls[:level] if ls.key?(:level)
18
+ logger_hash[:log_file] = ls[:log_file] if ls.key?(:log_file)
19
+ logger_hash[:trace] = ls[:trace] if ls.key?(:trace)
20
+ logger_hash[:extended] = ls[:extended] if ls.key?(:extended)
21
+ end
22
+
23
+ @log = Legion::Logging::Logger.new(**logger_hash)
24
+ end
25
+
26
+ private
27
+
28
+ def derive_log_tag
29
+ if respond_to?(:lex_filename)
30
+ fname = lex_filename
31
+ return fname.is_a?(Array) ? fname.first : fname
32
+ end
33
+
34
+ name = respond_to?(:ancestors) ? ancestors.first.to_s : self.class.to_s
35
+ parts = name.split('::')
36
+ ext_idx = parts.index('Extensions')
37
+ target = if ext_idx && parts[ext_idx + 1]
38
+ parts[ext_idx + 1]
39
+ else
40
+ parts.last
41
+ end
42
+ target.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
43
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
44
+ .downcase
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module Logging
5
- VERSION = '1.3.1'
5
+ VERSION = '1.3.3'
6
6
  end
7
7
  end
@@ -7,6 +7,7 @@ require 'legion/logging/builder'
7
7
  require 'legion/logging/hooks'
8
8
  require 'legion/logging/event_builder'
9
9
  require 'legion/logging/async_writer'
10
+ require 'legion/logging/helper'
10
11
 
11
12
  require 'json'
12
13
  require 'logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
@@ -60,6 +60,7 @@ files:
60
60
  - lib/legion/logging/async_writer.rb
61
61
  - lib/legion/logging/builder.rb
62
62
  - lib/legion/logging/event_builder.rb
63
+ - lib/legion/logging/helper.rb
63
64
  - lib/legion/logging/hooks.rb
64
65
  - lib/legion/logging/logger.rb
65
66
  - lib/legion/logging/methods.rb