Module: Foam::Otel::LoggerBridge::Patch
- Defined in:
- lib/foam/otel/logger_bridge.rb
Overview
The prepend. Logger#add is the single funnel (debug/info/warn/error/
fatal/unknown/log all land here). The stdlib's lazy-block contract is
preserved exactly: a filtered severity never evaluates the block (the
block form exists to avoid that cost), and an accepted block is
evaluated ONCE — resolved here, handed down as the message. The host's
own log write always happens FIRST; the bridge emit never precedes or
delays it.
Instance Method Summary collapse
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/foam/otel/logger_bridge.rb', line 143 def add(severity, = nil, progname = nil, &block) effective = severity || ::Logger::UNKNOWN return super unless Foam::Otel::LoggerBridge.emit? && effective >= level && foam_otel_bridgeable? own_progname = begin self.progname rescue StandardError nil end if .nil? && block # stdlib evaluates an accepted block exactly ONCE and lets its # raise propagate with nothing logged — same here, by NOT rescuing: # a rescue-then-`super` would re-invoke the caller's block (double # side effects on the raise path). resolved = block.call result = super(severity, resolved, progname) # block consumed exactly once Foam::Otel::LoggerBridge.emit(self, effective, resolved, progname || own_progname) else result = super # stdlib semantics: message absent → progname IS the message and # the logger's own progname labels it. resolved = .nil? ? progname : label = .nil? ? own_progname : (progname || own_progname) Foam::Otel::LoggerBridge.emit(self, effective, resolved, label) end result end |