Class: Stipa::Logger
- Inherits:
-
Object
- Object
- Stipa::Logger
- Defined in:
- lib/stipa/logger.rb
Overview
Structured, leveled logger that writes one logfmt line per event.
Format (parseable by Splunk, Datadog, Loki, grep):
time=2026-03-18T12:00:00.123Z level=INFO req_id=a1b2c3d4 method=GET
path=/users status=200 bytes_in=0 bytes_out=412
Thread-safe via Monitor (reentrant mutex — safe when a log call triggers another log call from a rescue block in the same thread).
Constant Summary collapse
- LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
Instance Method Summary collapse
- #debug(msg, **fields) ⇒ Object
- #error(msg, **fields) ⇒ Object
-
#info(req: nil, res: nil, bytes_in: 0, bytes_out: 0, **extra) ⇒ Object
Log a completed request/response cycle.
-
#initialize(output: $stdout, level: :info) ⇒ Logger
constructor
A new instance of Logger.
- #warn(msg, **fields) ⇒ Object
Constructor Details
Instance Method Details
#debug(msg, **fields) ⇒ Object
39 |
# File 'lib/stipa/logger.rb', line 39 def debug(msg, **fields); log(:debug, msg, **fields); end |
#error(msg, **fields) ⇒ Object
38 |
# File 'lib/stipa/logger.rb', line 38 def error(msg, **fields); log(:error, msg, **fields); end |
#info(req: nil, res: nil, bytes_in: 0, bytes_out: 0, **extra) ⇒ Object
Log a completed request/response cycle. Called by Connection.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/stipa/logger.rb', line 22 def info(req: nil, res: nil, bytes_in: 0, bytes_out: 0, **extra) return if @level > LEVELS[:info] fields = { time: utc_now, level: 'INFO', req_id: req&.id || '-', method: req&.method || '-', path: req&.path || '-', status: res&.status || '-', bytes_in: bytes_in, bytes_out: bytes_out, }.merge(extra) write(logfmt(fields)) end |
#warn(msg, **fields) ⇒ Object
37 |
# File 'lib/stipa/logger.rb', line 37 def warn(msg, **fields); log(:warn, msg, **fields); end |