Line data Source code
1 : import type { LogRecord } from './log_buffer.js';
2 : import { LogLevel } from './log_buffer.js';
3 : import { Logger } from './logger.js';
4 :
5 : /// A log record for tests, an info message unless overridden
6 1 : export function testLogRecord(fields: Partial<LogRecord> = {}): LogRecord {
7 1 : return {
8 1 : timestamp: 0,
9 1 : level: LogLevel.Info,
10 1 : target: 'test',
11 1 : message: 'test message',
12 1 : context: null,
13 1 : tracing: null,
14 1 : keyValues: {},
15 1 : ...fields,
16 1 : };
17 1 : }
18 :
19 1 : export class TestLogger extends Logger {
20 1 : constructor() {
21 1 : super();
22 1 : }
23 :
24 : /// Destroy the logger
25 0 : public async destroy(): Promise<void> { }
26 :
27 : /// Helper to flush pending records
28 1 : protected flushPendingRecords(): void {
29 1 : if (this.pendingRecords.length == 0) {
30 0 : return;
31 : }
32 1 : const pending = this.pendingRecords;
33 1 : this.pendingRecords = [];
34 1 : for (let i = 0; i < pending.length; ++i) {
35 1 : const record = pending[i];
36 1 : this.outputBuffer.push(record);
37 1 : }
38 1 : }
39 1 : };
|