class Capsium::LogBuffer
A small thread-safe ring buffer of timestamped log entries with a fixed capacity: when full, the oldest entry is dropped. The reactor records key serving events here and exposes the most recent lines through the /package/:id/logs introspection endpoint.
Constants
- DEFAULT_CAPACITY
- Entry
-
One buffer entry: a UTC timestamp and a message.
Attributes
capacity
[R]
Integer
Public Class Methods
(?capacity: Integer capacity) → void
Source
# File lib/capsium/log_buffer.rb, line 21 def initialize(capacity: DEFAULT_CAPACITY) raise ArgumentError, "capacity must be at least 1" if capacity < 1 @capacity = capacity @entries = [] @mutex = Mutex.new end
Public Instance Methods
(String message, ?timestamp: Time timestamp) → LogBuffer
Source
# File lib/capsium/log_buffer.rb, line 29 def add(message, timestamp: Time.now) @mutex.synchronize do @entries.shift if @entries.size >= @capacity @entries << Entry.new(timestamp: timestamp, message: message) end self end
(Integer count) → Array[Entry]
Source
# File lib/capsium/log_buffer.rb, line 38 def last(count) @mutex.synchronize { @entries.last(count) } end
The last count entries, oldest first.
(Integer count) → Array[String]
Source
# File lib/capsium/log_buffer.rb, line 43 def lines(count) last(count).map(&:line) end
The last count entries as formatted lines, oldest first.