logger.ts 780 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import { sanitizeForMetrics } from './metrics'

abstract class Logger {
  log(msg: string) {
    const date = new Date()
    process.stderr.write(`[${date.toISOString()}] ${msg}\n`)
  }
}

export class ActorLogger extends Logger {
  private readonly name: string

  constructor(name: string) {
    super()
    this.name = name
  }

  log(msg: string) {
    super.log(`[actor:${sanitizeForMetrics(this.name)}] ${msg}`)
  }
}

export class WorkerLogger extends Logger {
  private readonly name: string

  private readonly workerId: number

  constructor(name: string, workerId: number) {
    super()
    this.name = name
    this.workerId = workerId
  }

  log(msg: string) {
    super.log(
      `[bench:${sanitizeForMetrics(this.name)}] [wid:${this.workerId}] ${msg}`
    )
  }
}