diff --git a/.changeset/cuddly-radios-buy.md b/.changeset/cuddly-radios-buy.md new file mode 100644 index 00000000..6ae35987 --- /dev/null +++ b/.changeset/cuddly-radios-buy.md @@ -0,0 +1,5 @@ +--- +"@livekit/agents": patch +--- + +standardize logging diff --git a/agents/src/audio.ts b/agents/src/audio.ts index da1ec2de..d4ae7fa7 100644 --- a/agents/src/audio.ts +++ b/agents/src/audio.ts @@ -10,6 +10,7 @@ export class AudioByteStream { #numChannels: number; #bytesPerFrame: number; #buf: Int8Array; + #logger = log(); constructor(sampleRate: number, numChannels: number, samplesPerChannel: number | null = null) { this.#sampleRate = sampleRate; @@ -46,7 +47,7 @@ export class AudioByteStream { flush(): AudioFrame[] { if (this.#buf.length % (2 * this.#numChannels) !== 0) { - log().warn('AudioByteStream: incomplete frame during flush, dropping'); + this.#logger.warn('AudioByteStream: incomplete frame during flush, dropping'); return []; } diff --git a/agents/src/cli.ts b/agents/src/cli.ts index 987850f3..430ced2f 100644 --- a/agents/src/cli.ts +++ b/agents/src/cli.ts @@ -18,6 +18,7 @@ type CliArgs = { const runWorker = async (args: CliArgs) => { initializeLogger({ pretty: !args.production, level: args.opts.logLevel }); + const logger = log(); // though `production` is defined in WorkerOptions, it will always be overriddden by CLI. const { production: _, ...opts } = args.opts; // eslint-disable-line @typescript-eslint/no-unused-vars @@ -25,7 +26,7 @@ const runWorker = async (args: CliArgs) => { if (args.room) { worker.event.once('worker_registered', () => { - log().info(`connecting to room ${args.room}`); + logger.info(`connecting to room ${args.room}`); worker.simulateJob(args.room!, args.participantIdentity); }); } @@ -33,21 +34,21 @@ const runWorker = async (args: CliArgs) => { process.once('SIGINT', async () => { // allow C-c C-c for force interrupt process.once('SIGINT', () => { - log().info('worker closed forcefully'); + logger.info('worker closed forcefully'); process.exit(130); // SIGINT exit code }); if (args.production) { await worker.drain(); } await worker.close(); - log().info('worker closed'); + logger.info('worker closed'); process.exit(130); // SIGINT exit code }); try { await worker.run(); } catch { - log().fatal('worker failed'); + logger.fatal('worker failed'); process.exit(1); } }; diff --git a/agents/src/http_server.ts b/agents/src/http_server.ts index 8d45f691..76a0cb0c 100644 --- a/agents/src/http_server.ts +++ b/agents/src/http_server.ts @@ -13,6 +13,7 @@ export class HTTPServer { host: string; port: number; app: Server; + #logger = log(); constructor(host: string, port: number) { this.host = host; @@ -34,7 +35,7 @@ export class HTTPServer { if (err) reject(err); const address = this.app.address(); if (typeof address! !== 'string') { - log().info(`Server is listening on port ${address!.port}`); + this.#logger.info(`Server is listening on port ${address!.port}`); } resolve(); }); diff --git a/agents/src/transcription.ts b/agents/src/transcription.ts index b7ebd486..5f5b3534 100644 --- a/agents/src/transcription.ts +++ b/agents/src/transcription.ts @@ -25,6 +25,7 @@ export class BasicTranscriptionForwarder implements TranscriptionForwarder { #charsPerSecond: number = this.#DEFAULT_CHARS_PER_SECOND; #messageId: string; #isRunning: boolean = false; + #logger = log(); currentCharacterIndex: number = 0; constructor(room: Room, participantIdentity: string, trackSid: string, messageId: string) { @@ -38,7 +39,7 @@ export class BasicTranscriptionForwarder implements TranscriptionForwarder { if (!this.#isRunning) { this.#isRunning = true; this.#startPublishingLoop().catch((error) => { - log().error('Error in publishing loop:', error); + this.#logger.error('Error in publishing loop:', error); this.#isRunning = false; }); }