Class: Errsight::Logger
- Inherits:
-
Logger
- Object
- Logger
- Errsight::Logger
- Defined in:
- lib/errsight/logger.rb
Overview
A Logger-compatible class that forwards log entries to Errsight and optionally delegates to a backing logger.
Constant Summary collapse
- LEVEL_MAP =
{ DEBUG => :debug, INFO => :info, WARN => :warning, ERROR => :error, FATAL => :fatal, UNKNOWN => :info }.freeze
- LEVEL_ORDER =
%i[debug info warning error fatal].freeze
- EXCEPTION_FRAME_RE =
ActionDispatch::DebugExceptions logs a fully-formatted exception report via Rails.logger.fatal — class+msg, then a backtrace. Forwarding that blob as a single Event.message produces a giant title with no real backtrace column. The Rack CaptureMiddleware handles the underlying exception with structured fields, so we suppress these dumps here.
/:\d+:in ['`]/.freeze
- EXCEPTION_FRAME_THRESHOLD =
3
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object (also: #log)
-
#initialize(backing_logger = nil) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(backing_logger = nil) ⇒ Logger
Returns a new instance of Logger.
26 27 28 29 |
# File 'lib/errsight/logger.rb', line 26 def initialize(backing_logger = nil) super(IO::NULL) @backing_logger = backing_logger end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object Also known as: log
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/errsight/logger.rb', line 31 def add(severity, = nil, progname = nil, &block) # Forward to the backing logger if present @backing_logger&.add(severity, , progname, &block) # Cheap early-return: skip all allocations when Errsight is disabled # or this severity is below the configured threshold. Rails.logger can # fire thousands of times per request at :debug; this path matters. config = Errsight.configuration return true unless config.enabled? level = LEVEL_MAP[severity] || :info return true if LEVEL_ORDER.index(level).to_i < LEVEL_ORDER.index(config.min_level).to_i = block_given? ? yield : ||= progname return true if .nil? = .to_s return true if exception_dump?() = {} if (request_id = Thread.current[:errsight_request_id]) [:request_id] = request_id end Errsight.log(level: level, message: , metadata: ) true end |