docs: 基本完成初版数据库设计
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { test } from 'node:test';
|
||||
import { AppLogger } from '../src/logging/app-logger';
|
||||
|
||||
test('日志为单行 JSON,递归脱敏并安全处理循环对象与 bigint', () => {
|
||||
const output: string[] = [];
|
||||
const logger = new AppLogger('info', (line) => output.push(line));
|
||||
const nested: Record<string, unknown> = {
|
||||
password: 'private-password',
|
||||
amount: 9n,
|
||||
};
|
||||
nested.self = nested;
|
||||
logger.log('test_event', {
|
||||
authorization: 'Bearer private-token',
|
||||
nested,
|
||||
body: { code: 'login-secret' },
|
||||
});
|
||||
logger.debug('hidden');
|
||||
assert.equal(output.length, 1);
|
||||
const log = JSON.parse(output[0]!);
|
||||
assert.equal(log.context.authorization, '[REDACTED]');
|
||||
assert.equal(log.context.nested.password, '[REDACTED]');
|
||||
assert.equal(log.context.nested.self, '[Circular]');
|
||||
assert.equal(log.context.nested.amount, '9');
|
||||
assert.equal(log.context.body, '[REDACTED]');
|
||||
assert.ok(!output[0]!.includes('private-'));
|
||||
assert.ok(!output[0]!.includes('login-secret'));
|
||||
});
|
||||
Reference in New Issue
Block a user