Module: Pgbus::LogFormatter
- Defined in:
- lib/pgbus/log_formatter.rb
Overview
Defined Under Namespace
Class Method Summary collapse
- .current_context ⇒ Object
- .tid ⇒ Object
-
.with_context(hash) ⇒ Object
Thread-local context for structured logging.
Class Method Details
.current_context ⇒ Object
37 38 39 |
# File 'lib/pgbus/log_formatter.rb', line 37 def current_context Thread.current[:pgbus_log_context] ||= {} end |
.tid ⇒ Object
22 23 24 |
# File 'lib/pgbus/log_formatter.rb', line 22 def tid Thread.current[:pgbus_tid] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36) end |
.with_context(hash) ⇒ Object
Thread-local context for structured logging. Works like Sidekiq::Context — any key/value pairs set via with_context appear in the JSON output under the “ctx” key.
29 30 31 32 33 34 35 |
# File 'lib/pgbus/log_formatter.rb', line 29 def with_context(hash) orig = current_context.dup current_context.merge!(hash) yield ensure Thread.current[:pgbus_log_context] = orig end |