mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-07-26 00:55:03 +02:00
* enhance: プロセスのライフサイクルに合わせてlogger初期化・終了+logger設定機構の追加 * fix --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { describe, expect, test, vi } from 'vitest';
|
|
import type { LogRecord } from '@/logging/types.js';
|
|
import { BootstrapConsoleBackend } from '@/logging/BootstrapConsoleBackend.js';
|
|
|
|
function createRecord(overrides: Partial<LogRecord> = {}): LogRecord {
|
|
return {
|
|
level: 'error',
|
|
message: 'configuration failed',
|
|
context: [{ name: 'core' }, { name: 'boot' }],
|
|
timestamp: '2025-01-02T03:04:05.678Z',
|
|
loggerName: 'core.boot',
|
|
processId: 1234,
|
|
isPrimary: true,
|
|
workerId: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('BootstrapConsoleBackend', () => {
|
|
test('writes a minimal line with legacy data', () => {
|
|
const output = vi.fn();
|
|
const backend = new BootstrapConsoleBackend({ output });
|
|
const data = { detail: 'failed' };
|
|
|
|
backend.write(createRecord({ compatibility: { data } }));
|
|
|
|
expect(output).toHaveBeenCalledWith('2025-01-02T03:04:05.678Z ERROR *\t[core.boot]\tconfiguration failed', data);
|
|
});
|
|
|
|
test('writes structured details without depending on Pretty formatting', () => {
|
|
const output = vi.fn();
|
|
const backend = new BootstrapConsoleBackend({ output });
|
|
|
|
backend.write(createRecord({
|
|
eventName: 'config.load.failed',
|
|
attributes: { path: '.config/default.yml' },
|
|
error: { type: 'Error', message: 'not found' },
|
|
}));
|
|
|
|
expect(output).toHaveBeenCalledWith(
|
|
'2025-01-02T03:04:05.678Z ERROR *\t[core.boot]\tconfiguration failed',
|
|
{
|
|
eventName: 'config.load.failed',
|
|
attributes: { path: '.config/default.yml' },
|
|
error: { type: 'Error', message: 'not found' },
|
|
},
|
|
);
|
|
});
|
|
});
|