RateLimitedLogger

org.llm4s.util.RateLimitedLogger
See theRateLimitedLogger companion object
final class RateLimitedLogger(logger: Logger, throttleSeconds: Long, throttleCount: Int)

Thread-safe rate-limited logger to prevent log spam. Logs at most once per time window OR once per count threshold, whichever comes first. Aggregates skipped count between log messages.

Thread-safety via AtomicLong and AtomicInteger ensures visibility and atomic operations. Multiple threads may pass shouldLog check, but compareAndSet ensures only one logs. Minor event count drift is acceptable for best-effort logging.

SLF4J dependency provided transitively via logback-classic.

Value parameters

logger

SLF4J logger instance

throttleCount

Maximum events before forcing a log

throttleSeconds

Minimum seconds between log messages

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def reset(): Unit

Reset the rate limiter state. Useful for testing or explicit state clearing.

Reset the rate limiter state. Useful for testing or explicit state clearing.

Attributes

def warn(message: => String): Boolean

Log a warning message with rate limiting (thread-safe).

Log a warning message with rate limiting (thread-safe).

Value parameters

message

Warning message (call-by-name, only evaluated if logged)

Attributes

Returns

true if message was logged, false if throttled