Skip to content

Utilities

The utils module houses reusable internal utilities including structured JSON logging, low-overhead performance counters, and memory object pools. These helpers are specifically optimized to minimize garbage collection pressure on high-throughput hot paths. They are used universally across core routing and policy execution layers.

SymbolKindSignaturePurpose
LogLevelenumenum LogLevelEnum export for LogLevel.
LoggerConfiginterfaceinterface LoggerConfigInterface export for LoggerConfig.
LogContextinterfaceinterface LogContextInterface export for LogContext.
Loggerinterfaceinterface LoggerInterface export for Logger.
createLoggerfunctionfunction createLogger(config: Partial<LoggerConfig> = {}): LoggerFunction export for createLogger.
loggerconstconst logger = createLogger(Const export for logger.
StructuredLoggerclassclass StructuredLoggerClass export for StructuredLogger.
createRequestLoggerfunctionfunction createRequestLogger()Function export for createRequestLogger.
logSlowRequestfunctionfunction logSlowRequest(method: string, path: string, latencyMs: number, threshold: numberFunction export for logSlowRequest.
MetricsCollectorclassclass MetricsCollectorMetrics collector for gateway performance monitoring Uses lock-free counters and circular buffers
metricsconstconst metrics = new MetricsCollector()Export singleton instance
Poolableinterfaceinterface PoolablePoolable object interface Objects in pool must implement reset method
PoolStatsinterfaceinterface PoolStatsPool statistics for monitoring
PoolFactorytypetype PoolFactory<T> = () => TFactory function for creating new pool objects
ObjectPoolclassclass ObjectPool<T extends Poolable>Generic object pool implementation Fixed-size pool with overflow handling
BufferPoolclassclass BufferPoolBuffer pool for reusing byte buffers Uses wrapper class to avoid monkey-patching Buffer prototype

Structured JSON logger writing directly to stdout with configurable log level filters.

Fixed-size recycling pool for context objects to avoid per-request memory allocation churn.

Lightweight ring buffer tracking timing histograms and counter increments.

  • src/utils/logger.ts
  • src/utils/metrics.ts
  • src/utils/pool.ts