Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions assistant/src/migrations/log.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import pino from 'pino';
import { logSerializers } from '../util/log-redact.js';

/**
* Stderr-only logger for migration code. Using the pino logger during
* migration is unsafe because pino initialization calls ensureDataDir(),
* which pre-creates workspace destination directories and causes migration
* moves to no-op.
* Standalone pino instance for migration code. This must NOT use getLogger()
* because that triggers ensureDataDir(), which pre-creates workspace
* destination directories and causes migration moves to no-op.
*
* Writes to stderr only — no log files that might not exist yet.
*/
const migrationLogger: pino.Logger = pino(
{ name: 'migration', level: 'info', serializers: logSerializers },
pino.destination(2),
);

export function migrationLog(level: 'info' | 'warn' | 'debug', msg: string, data?: Record<string, unknown>): void {
if (level === 'debug') return; // suppress debug-level migration noise
const prefix = level === 'warn' ? 'WARN' : 'INFO';
const extra = data ? ' ' + JSON.stringify(data) : '';
process.stderr.write(`[migration] ${prefix}: ${msg}${extra}\n`);
if (level === 'debug') return;
if (data) {
migrationLogger[level](data, msg);
} else {
migrationLogger[level](msg);
}
}