legion-logging 1.5.2 → 1.5.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/CLAUDE.md +29 -75
- data/lib/legion/logging/helper.rb +12 -2
- data/lib/legion/logging/methods.rb +26 -7
- data/lib/legion/logging/settings.rb +5 -4
- data/lib/legion/logging/version.rb +1 -1
- 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: f751e228eb4c00edae10784b3edf4176afb2f84ec7a8df1525a9c8432145c50f
|
|
4
|
+
data.tar.gz: 728db26335f6bffdcef54523760d9b8051615f0bee280ac01a897a3373b3403f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ba593790cf603ab542162e685c97450f7db2d18da76dd288981317ecf627b708a391e2b0f1eecfef43e3a308f0391a89a6bc636ab3216c6450a973d653b7e3e
|
|
7
|
+
data.tar.gz: 5c6fb87b90d197c3f70e0d69e1d5a3a13c55083aa1f8ebbd79676ff8926b12686e3fa9b2df91286ac2a216ace987863eb719b21df8693e3f0981768a2f70f748
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Legion::Logging Changelog
|
|
2
2
|
|
|
3
|
+
## [1.5.3] - 2026-05-13
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `backtrace_limit:` kwarg on `log_exception` and `handle_exception` (nil=full, 0=suppress, N=cap at N frames)
|
|
7
|
+
- `backtrace_limit` key in `Legion::Logging::Settings.default` (defaults to nil — full backtraces)
|
|
8
|
+
- Settings-driven default reads from `Legion::Settings[:logging][:backtrace_limit]` when no explicit kwarg is passed
|
|
9
|
+
|
|
3
10
|
## [1.5.2] - 2026-04-27
|
|
4
11
|
|
|
5
12
|
### Changed
|
data/CLAUDE.md
CHANGED
|
@@ -1,92 +1,46 @@
|
|
|
1
|
-
# legion-logging
|
|
1
|
+
# legion-logging
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
- **Parent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
|
|
5
|
-
|
|
6
|
-
## Purpose
|
|
7
|
-
|
|
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.
|
|
3
|
+
Structured logging framework for LegionIO. Provides colorized console output (Rainbow), structured JSON logging, and a consistent interface across all Legion gems and extensions.
|
|
9
4
|
|
|
10
5
|
**GitHub**: https://github.com/LegionIO/legion-logging
|
|
11
|
-
**Version**: 1.5.
|
|
12
|
-
**License**: Apache-2.0
|
|
6
|
+
**Version**: 1.5.3
|
|
13
7
|
|
|
14
8
|
## Architecture
|
|
15
9
|
|
|
16
10
|
```
|
|
17
11
|
Legion::Logging (singleton module)
|
|
18
|
-
├── Methods #
|
|
19
|
-
├── Builder # Output destination
|
|
20
|
-
├── AsyncWriter # Non-blocking SizedQueue-backed writer thread
|
|
21
|
-
├── Hooks # Callback registry for fatal/error/warn events
|
|
22
|
-
├── EventBuilder # Structured event payload
|
|
23
|
-
├── Helper # Injectable log mixin for LEX extensions
|
|
24
|
-
├──
|
|
25
|
-
├──
|
|
26
|
-
├──
|
|
27
|
-
├──
|
|
28
|
-
├──
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# Module-level writers (pluggable lambda slots replacing old Hooks for AMQP forwarding)
|
|
35
|
-
Legion::Logging.log_writer # -> lambda(->(event, routing_key:) {})
|
|
36
|
-
Legion::Logging.exception_writer # -> lambda(->(event, routing_key:, headers:, properties:) {})
|
|
12
|
+
├── Methods # debug, info, warn, error, fatal, unknown; log_exception
|
|
13
|
+
├── Builder # Output destination, log level, formatter, async: keyword
|
|
14
|
+
├── AsyncWriter # Non-blocking SizedQueue-backed writer thread
|
|
15
|
+
├── Hooks # Callback registry for fatal/error/warn events
|
|
16
|
+
├── EventBuilder # Structured event payload + fingerprint for dedup
|
|
17
|
+
├── Helper # Injectable log mixin for LEX extensions
|
|
18
|
+
├── TaggedLogger # Prepends structured tags to each message
|
|
19
|
+
├── CategoryRegistry # Named log categories with expected_fields
|
|
20
|
+
├── SIEMExporter # PHI-redacting SIEM export (Splunk HEC, ELK)
|
|
21
|
+
├── Shipper # Buffered forwarding (FileTransport, HttpTransport)
|
|
22
|
+
├── Redactor # PII/PHI + secret pattern redaction (opt-in)
|
|
23
|
+
└── MultiIO # Write to multiple destinations simultaneously
|
|
24
|
+
|
|
25
|
+
# Module-level writer lambdas (pluggable forwarding slots)
|
|
26
|
+
Legion::Logging.log_writer # ->(event, routing_key:) {}
|
|
27
|
+
Legion::Logging.exception_writer # ->(event, routing_key:, headers:, properties:) {}
|
|
37
28
|
```
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- **Singleton Module**: `Legion::Logging` uses `class << self` — called directly: `Legion::Logging.info("msg")`
|
|
42
|
-
- **Rainbow Colorization**: Console output uses Rainbow gem for colored terminal output. Color auto-disabled in JSON format and when writing to a log file.
|
|
43
|
-
- **Setup Method**: `Legion::Logging.setup(level:, format:, async:, **options)` configures output, level, format, and async mode. Increments `configuration_generation` on each call.
|
|
44
|
-
- **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[:logging][:async][:buffer_size]` (default 10,000). Back-pressure: callers block when buffer is full.
|
|
45
|
-
- **Structured JSON**: `format: :json` in settings outputs machine-parseable JSON log lines (disables color)
|
|
46
|
-
- **Shared Interface**: Same method signature (`info`, `warn`, `error`, etc.) across all Legion components
|
|
47
|
-
- **MultiIO**: Splits writes to stdout and a log file simultaneously (used by Builder when `log_file` is set)
|
|
48
|
-
- **SIEMExporter**: PHI redaction (SSN, phone, MRN, DOB patterns), `export_to_splunk` (HEC), `format_for_elk`
|
|
49
|
-
- **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. Hooks fire on the async writer thread; event context captured on caller thread.
|
|
50
|
-
- **EventBuilder**: Builds structured event hashes from log context (caller location, exception info, lex identity, gem metadata). All from in-memory data, zero IO. `fingerprint` produces MD5 for dedup in log aggregation.
|
|
51
|
-
- **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.
|
|
52
|
-
- **Writer Lambdas**: `log_writer` and `exception_writer` are module-level lambda slots for forwarding to external systems (AMQP, etc.). Default implementations are no-ops. Set via `Legion::Logging.log_writer = lambda`.
|
|
53
|
-
- **CategoryRegistry**: Named log categories with description and expected_fields. Register via `Legion::Logging.register_category`. Used for structured log validation.
|
|
54
|
-
- **Redactor**: Opt-in PII/PHI redaction (`logging.redaction.enabled: true`). Guards against Settings recursive init via `@loader` ivar check. Patterns: SSN, phone, MRN, DOB, Vault tokens, JWTs, bearer tokens, lease IDs.
|
|
30
|
+
## Key Patterns
|
|
55
31
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
| Path | Purpose |
|
|
65
|
-
|------|---------|
|
|
66
|
-
| `lib/legion/logging.rb` | Module entry point |
|
|
67
|
-
| `lib/legion/logging/methods.rb` | Log level methods |
|
|
68
|
-
| `lib/legion/logging/builder.rb` | Output config and formatter (async: keyword) |
|
|
69
|
-
| `lib/legion/logging/async_writer.rb` | Non-blocking SizedQueue-backed writer thread with back-pressure |
|
|
70
|
-
| `lib/legion/logging/helper.rb` | Injectable log mixin for LEX extensions |
|
|
71
|
-
| `lib/legion/logging/logger.rb` | Core logger setup |
|
|
72
|
-
| `lib/legion/logging/multi_io.rb` | Multi-output IO (write to multiple destinations simultaneously) |
|
|
73
|
-
| `lib/legion/logging/siem_exporter.rb` | PHI-redacting SIEM export helpers (Splunk HEC, ELK format) |
|
|
74
|
-
| `lib/legion/logging/hooks.rb` | Callback registry (fatal/error/warn hook arrays, enable/disable/clear) |
|
|
75
|
-
| `lib/legion/logging/event_builder.rb` | Structured event payload builder; `fingerprint` for MD5 dedup |
|
|
76
|
-
| `lib/legion/logging/tagged_logger.rb` | Logger wrapper that prepends structured tags to each message |
|
|
77
|
-
| `lib/legion/logging/category_registry.rb` | Named log category registration and lookup |
|
|
78
|
-
| `lib/legion/logging/method_tracer.rb` | Method call tracing instrumentation (call/return, formatted args) |
|
|
79
|
-
| `lib/legion/logging/shipper.rb` | Buffered log event forwarding to external systems |
|
|
80
|
-
| `lib/legion/logging/shipper/file_transport.rb` | File-based log shipper transport |
|
|
81
|
-
| `lib/legion/logging/shipper/http_transport.rb` | HTTP-based log shipper transport |
|
|
82
|
-
| `lib/legion/logging/siem_exporter.rb` | PHI-redacting SIEM export (Splunk HEC, ELK format) |
|
|
83
|
-
| `lib/legion/logging/redactor.rb` | PII/PHI + secret pattern redaction (opt-in) |
|
|
84
|
-
| `lib/legion/logging/version.rb` | VERSION constant |
|
|
32
|
+
- **Singleton module** — `class << self`; called directly: `Legion::Logging.info("msg")`
|
|
33
|
+
- **Async by default** — `setup` enables async logging; fatal bypasses queue. Buffer size via `Settings[:logging][:async][:buffer_size]` (default 10,000). Back-pressure blocks callers when full.
|
|
34
|
+
- **Structured JSON** — `format: :json` outputs machine-parseable JSON lines (disables color)
|
|
35
|
+
- **Helper mixin** — `Legion::Logging::Helper` injects into LEX extensions; derives tags from `segments`, `lex_filename`, or class name
|
|
36
|
+
- **Writer lambdas** — `log_writer` and `exception_writer` are module-level lambda slots for forwarding to external systems (AMQP, etc.). Default no-ops.
|
|
37
|
+
- **Redactor** — Opt-in (`logging.redaction.enabled: true`). Patterns: SSN, phone, MRN, DOB, Vault tokens, JWTs, bearer tokens, lease IDs. Guards against Settings recursive init.
|
|
38
|
+
- **Hook callbacks** — `on_fatal`, `on_error`, `on_warn` register procs; gated by `enable_hooks!`/`disable_hooks!`; fire on async writer thread
|
|
39
|
+
- **EventBuilder** — Structured event hashes from log context (caller, exception, lex identity). `fingerprint` produces MD5 for dedup.
|
|
85
40
|
|
|
86
41
|
## Role in LegionIO
|
|
87
42
|
|
|
88
|
-
|
|
43
|
+
Foundational gem — dependency of `legion-cache`, `legion-data`, and `LegionIO`. First module initialized during `Legion::Service` startup.
|
|
89
44
|
|
|
90
45
|
---
|
|
91
|
-
|
|
92
46
|
**Maintained By**: Matthew Iverson (@Esity)
|
|
@@ -487,8 +487,18 @@ module Legion
|
|
|
487
487
|
context_line = build_context_line(event)
|
|
488
488
|
lines << " #{context_line}" unless context_line.empty?
|
|
489
489
|
|
|
490
|
-
|
|
491
|
-
|
|
490
|
+
max_frames = if event[:backtrace_limit].nil?
|
|
491
|
+
defined?(Legion::Settings) ? Legion::Settings[:logging][:backtrace_limit] : nil
|
|
492
|
+
else
|
|
493
|
+
event[:backtrace_limit]
|
|
494
|
+
end
|
|
495
|
+
unless max_frames&.zero?
|
|
496
|
+
bt = exception.backtrace
|
|
497
|
+
if bt&.any?
|
|
498
|
+
frames = max_frames ? bt.first(max_frames) : bt
|
|
499
|
+
frames.each { |frame| lines << " #{frame}" }
|
|
500
|
+
end
|
|
501
|
+
end
|
|
492
502
|
|
|
493
503
|
lines.join("\n")
|
|
494
504
|
end
|
|
@@ -102,17 +102,12 @@ module Legion
|
|
|
102
102
|
def log_exception(exception, level: :error, lex: nil, component_type: nil,
|
|
103
103
|
gem_name: nil, lex_version: nil, gem_path: nil,
|
|
104
104
|
source_code_uri: nil, handled: false, payload_summary: nil,
|
|
105
|
-
task_id: nil, **extra)
|
|
105
|
+
task_id: nil, backtrace_limit: nil, **extra)
|
|
106
106
|
level = level.to_sym if level.respond_to?(:to_sym)
|
|
107
107
|
# 1. Log human-readable line + backtrace to stdout/file (bypass writer callbacks)
|
|
108
108
|
msg = exception.respond_to?(:message) ? exception.message : exception.to_s
|
|
109
109
|
msg = maybe_redact(msg)
|
|
110
|
-
|
|
111
|
-
if bt.any?
|
|
112
|
-
lines = ["#{exception.class}: #{msg}"]
|
|
113
|
-
bt.each { |frame| lines << " #{frame}" }
|
|
114
|
-
msg = lines.join("\n")
|
|
115
|
-
end
|
|
110
|
+
msg = build_exception_log_message(exception, msg, backtrace_limit)
|
|
116
111
|
log.public_send(level, msg) if respond_to?(:log) && log.respond_to?(level)
|
|
117
112
|
|
|
118
113
|
# 2. Build rich exception event
|
|
@@ -155,6 +150,30 @@ module Legion
|
|
|
155
150
|
|
|
156
151
|
private
|
|
157
152
|
|
|
153
|
+
def resolve_backtrace_limit(explicit_limit)
|
|
154
|
+
return explicit_limit unless explicit_limit.nil?
|
|
155
|
+
return nil unless defined?(Legion::Settings)
|
|
156
|
+
|
|
157
|
+
Legion::Settings[:logging][:backtrace_limit]
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def build_exception_log_message(exception, msg, backtrace_limit)
|
|
161
|
+
max_frames = resolve_backtrace_limit(backtrace_limit)
|
|
162
|
+
bt = collect_backtrace_frames(exception, max_frames)
|
|
163
|
+
return msg unless bt.any?
|
|
164
|
+
|
|
165
|
+
lines = ["#{exception.class}: #{msg}"]
|
|
166
|
+
bt.each { |frame| lines << " #{frame}" }
|
|
167
|
+
lines.join("\n")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def collect_backtrace_frames(exception, max_frames)
|
|
171
|
+
return [] if max_frames&.zero?
|
|
172
|
+
|
|
173
|
+
frames = Array(exception.backtrace)
|
|
174
|
+
max_frames ? frames.first(max_frames) : frames
|
|
175
|
+
end
|
|
176
|
+
|
|
158
177
|
def maybe_redact(message)
|
|
159
178
|
return message unless message.is_a?(String)
|
|
160
179
|
return message unless redaction_enabled?
|