Skip to Content

Logging

Simloop includes a pluggable logging system for observability during simulation runs.

Log Levels

LevelDescription
debugDetailed tracing (event processing, scheduling)
infoGeneral information (lifecycle transitions)
warnWarnings (unhandled event types)
errorErrors
silentNo output

Set the minimum level via the logLevel configuration option:

const sim = new SimulationEngine<Events>({ logLevel: 'info', // only info, warn, error are shown });

Built-in Lifecycle Logging

The engine automatically logs lifecycle transitions and event processing at debug level:

  • Simulation start/stop/pause/resume
  • Event processing (type, time)
  • Warm-up threshold crossed

User Logging via ctx.log()

Inside handlers, use ctx.log() for application-level logging:

sim.on('customer:arrive', (event, ctx) => { ctx.log('debug', `Customer ${event.payload.customerId} arrived at t=${ctx.clock}`); ctx.log('info', 'Processing new arrival'); });

Custom Logger

By default, Simloop uses ConsoleLogger. You can provide a custom SimLogger implementation via the logger option to redirect output (files, structured logging, etc.):

import { SimulationEngine } from 'simloop'; import type { SimLogger, LogLevel } from 'simloop'; const myLogger: SimLogger = { log(level: LogLevel, message: string): void { // send to file, external service, etc. }, }; const sim = new SimulationEngine<Events>({ logger: myLogger, logLevel: 'debug', });

Hooks for Tracing

Lifecycle hooks provide additional observability:

sim.beforeEach((event, ctx) => { console.log(`[${ctx.clock.toFixed(2)}] Processing: ${event.type}`); }); sim.afterEach((event, ctx) => { console.log(`[${ctx.clock.toFixed(2)}] Done: ${event.type}`); }); sim.onEnd((ctx) => { console.log(`Simulation ended at t=${ctx.clock}`); });
Last updated on