Structured logging framework for LegionIO. Provides colorized console output (Rainbow), structured JSON logging, and a consistent interface across all Legion gems and extensions.
GitHub: https://github.com/LegionIO/legion-logging Version: 1.5.3
Legion::Logging (singleton module)
├── Methods # debug, info, warn, error, fatal, unknown; log_exception
├── Builder # Output destination, log level, formatter, async: keyword
├── AsyncWriter # Non-blocking SizedQueue-backed writer thread
├── Hooks # Callback registry for fatal/error/warn events
├── EventBuilder # Structured event payload + fingerprint for dedup
├── Helper # Injectable log mixin for LEX extensions
├── TaggedLogger # Prepends structured tags to each message
├── CategoryRegistry # Named log categories with expected_fields
├── SIEMExporter # PHI-redacting SIEM export (Splunk HEC, ELK)
├── Shipper # Buffered forwarding (FileTransport, HttpTransport)
├── Redactor # PII/PHI + secret pattern redaction (opt-in)
└── MultiIO # Write to multiple destinations simultaneously
# Module-level writer lambdas (pluggable forwarding slots)
Legion::Logging.log_writer # ->(event, routing_key:) {}
Legion::Logging.exception_writer # ->(event, routing_key:, headers:, properties:) {}
- Singleton module —
class << self; called directly:Legion::Logging.info("msg") - Async by default —
setupenables async logging; fatal bypasses queue. Buffer size viaSettings[:logging][:async][:buffer_size](default 10,000). Back-pressure blocks callers when full. - Structured JSON —
format: :jsonoutputs machine-parseable JSON lines (disables color) - Helper mixin —
Legion::Logging::Helperinjects into LEX extensions; derives tags fromsegments,lex_filename, or class name - Writer lambdas —
log_writerandexception_writerare module-level lambda slots for forwarding to external systems (AMQP, etc.). Default no-ops. - Redactor — Opt-in (
logging.redaction.enabled: true). Patterns: SSN, phone, MRN, DOB, Vault tokens, JWTs, bearer tokens, lease IDs. Guards against Settings recursive init. - Hook callbacks —
on_fatal,on_error,on_warnregister procs; gated byenable_hooks!/disable_hooks!; fire on async writer thread - EventBuilder — Structured event hashes from log context (caller, exception, lex identity).
fingerprintproduces MD5 for dedup.
Foundational gem — dependency of legion-cache, legion-data, and LegionIO. First module initialized during Legion::Service startup.
Maintained By: Matthew Iverson (@Esity)