legion-logging 1.5.1 → 1.5.2
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/.gitignore +2 -1
- data/CHANGELOG.md +5 -0
- data/README.md +35 -10
- data/lib/legion/logging/helper.rb +1 -6
- data/lib/legion/logging/methods.rb +1 -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: 57e4eef04828ffa39cae5277822be4f2f5264d4010b05e724dbb179f0af5b771
|
|
4
|
+
data.tar.gz: 740663a6979cf6b5c5d90a12bc8c43e0fcd989b8d8253269d8a1f1bf9aff9d03
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c590642e775a8f6ed7f87f9b4525049033c3e3f42635ea2e460e5b4ddd89e646a97d8744b80755a82db340ba6e813d8e95e3a8b27ffc17a63f8f3aee99e5b5a6
|
|
7
|
+
data.tar.gz: b812f47d57057a466655f22ae1f3922b6326a22fd40297ce602850069092efaf20ff40a6689ecbfe22a7498429bb3266df70ec40efb69617d11da045695155bd
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
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.5.
|
|
5
|
+
**Version**: 1.5.2
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -96,23 +96,46 @@ end
|
|
|
96
96
|
|
|
97
97
|
### Exception Logging
|
|
98
98
|
|
|
99
|
-
`log_exception` provides a single call for complete
|
|
99
|
+
`log_exception` provides a single call for complete exception logging with component context. It writes a human-readable exception line through the configured logger and publishes a structured exception event when an `exception_writer` is configured.
|
|
100
100
|
|
|
101
101
|
```ruby
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
begin
|
|
103
|
+
runner.call
|
|
104
|
+
rescue StandardError => e
|
|
105
|
+
Legion::Logging.log_exception(
|
|
106
|
+
e,
|
|
107
|
+
handled: true,
|
|
108
|
+
component_type: :runner,
|
|
109
|
+
lex: 'my_extension',
|
|
110
|
+
task_id: 'abc-123'
|
|
111
|
+
)
|
|
112
|
+
end
|
|
107
113
|
```
|
|
108
114
|
|
|
115
|
+
The synchronous log line includes the full Ruby backtrace. Legion does not truncate it to a fixed frame count or replace the tail with `... N more`, because the missing frames are often the useful part of production failures.
|
|
116
|
+
|
|
117
|
+
Structured exception events include:
|
|
118
|
+
|
|
119
|
+
- exception class and message
|
|
120
|
+
- full backtrace array
|
|
121
|
+
- caller file, line, and function where available
|
|
122
|
+
- log level and handled/unhandled status
|
|
123
|
+
- component type, lex name, gem name, version, and source path metadata
|
|
124
|
+
- task and thread context
|
|
125
|
+
- stable error fingerprint for deduplication
|
|
126
|
+
|
|
109
127
|
### Writer Lambdas
|
|
110
128
|
|
|
111
129
|
`log_writer` and `exception_writer` are pluggable lambda slots that replace the old Hooks system. Assign them to forward events to external systems:
|
|
112
130
|
|
|
113
131
|
```ruby
|
|
114
|
-
Legion::Logging.exception_writer =
|
|
115
|
-
|
|
132
|
+
Legion::Logging.exception_writer = lambda do |payload, routing_key:, headers:, properties:|
|
|
133
|
+
publish_to_amqp(payload, routing_key:, headers:, properties:)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
Legion::Logging.log_writer = lambda do |context, routing_key:|
|
|
137
|
+
publish_log(context, routing_key:)
|
|
138
|
+
end
|
|
116
139
|
```
|
|
117
140
|
|
|
118
141
|
### EventBuilder
|
|
@@ -121,7 +144,9 @@ Legion::Logging.log_writer = ->(context, routing_key:) { publish_log(context) }
|
|
|
121
144
|
|
|
122
145
|
### Redactor
|
|
123
146
|
|
|
124
|
-
`Legion::Logging::Redactor` redacts PII/PHI patterns (SSN, phone, MRN, DOB) plus Vault tokens, JWTs, bearer tokens, and lease IDs from log messages. Redaction is opt-in: load the module (for example via `require 'legion/logging/redactor'`) and enable it with `logging.redaction.enabled: true`. When loaded and enabled, it is wired into all log methods in the write path.
|
|
147
|
+
`Legion::Logging::Redactor` redacts PII/PHI patterns (SSN, email, phone, MRN, DOB, credit card) plus Vault tokens, JWTs, bearer tokens, `vault://` URIs, `lease://` URIs, and lease IDs from log messages. Redaction is opt-in for text log lines: load the module (for example via `require 'legion/logging/redactor'`) and enable it with `logging.redaction.enabled: true`. When loaded and enabled, it is wired into all log methods in the write path.
|
|
148
|
+
|
|
149
|
+
Structured exception events are redacted before publishing when the redactor is loaded. This includes event identity fields such as `user`, so email-shaped local usernames are not forwarded raw.
|
|
125
150
|
|
|
126
151
|
## Requirements
|
|
127
152
|
|
|
@@ -32,7 +32,6 @@ module Legion
|
|
|
32
32
|
'middleware' => :middleware
|
|
33
33
|
}.freeze
|
|
34
34
|
|
|
35
|
-
EXCEPTION_BACKTRACE_LIMIT = 10
|
|
36
35
|
EXCEPTION_PRIORITY = { warn: 0, error: 5, fatal: 9 }.freeze
|
|
37
36
|
EXCEPTION_COLORS = {
|
|
38
37
|
fatal: :darkred,
|
|
@@ -489,11 +488,7 @@ module Legion
|
|
|
489
488
|
lines << " #{context_line}" unless context_line.empty?
|
|
490
489
|
|
|
491
490
|
bt = exception.backtrace
|
|
492
|
-
if bt&.any?
|
|
493
|
-
bt.first(EXCEPTION_BACKTRACE_LIMIT).each { |frame| lines << " #{frame}" }
|
|
494
|
-
remaining = bt.length - EXCEPTION_BACKTRACE_LIMIT
|
|
495
|
-
lines << " ... #{remaining} more" if remaining.positive?
|
|
496
|
-
end
|
|
491
|
+
bt.each { |frame| lines << " #{frame}" } if bt&.any?
|
|
497
492
|
|
|
498
493
|
lines.join("\n")
|
|
499
494
|
end
|
|
@@ -109,11 +109,8 @@ module Legion
|
|
|
109
109
|
msg = maybe_redact(msg)
|
|
110
110
|
bt = Array(exception.backtrace)
|
|
111
111
|
if bt.any?
|
|
112
|
-
limit = defined?(Legion::Logging::Helper::EXCEPTION_BACKTRACE_LIMIT) ? Legion::Logging::Helper::EXCEPTION_BACKTRACE_LIMIT : 10
|
|
113
112
|
lines = ["#{exception.class}: #{msg}"]
|
|
114
|
-
bt.
|
|
115
|
-
remaining = bt.length - limit
|
|
116
|
-
lines << " ... #{remaining} more" if remaining.positive?
|
|
113
|
+
bt.each { |frame| lines << " #{frame}" }
|
|
117
114
|
msg = lines.join("\n")
|
|
118
115
|
end
|
|
119
116
|
log.public_send(level, msg) if respond_to?(:log) && log.respond_to?(level)
|