From 2dcb67085038108e5135cac0cbb3b1fdd2445516 Mon Sep 17 00:00:00 2001 From: Noel Date: Sun, 12 Mar 2023 15:00:24 -0700 Subject: [PATCH] Replace `reqId` with `req.id` (if it is available) --- src/formatters/json.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/formatters/json.ts b/src/formatters/json.ts index fe7a309..05ecfee 100644 --- a/src/formatters/json.ts +++ b/src/formatters/json.ts @@ -24,7 +24,7 @@ import { BaseFormatter, type LogRecord } from './base'; import { levelLabelNames, omit } from '../utils'; import { EOL, userInfo } from 'os'; -import { Lazy } from '@noelware/utils'; +import { hasOwnProperty, Lazy } from '@noelware/utils'; const username = new Lazy(() => { const info = userInfo(); @@ -42,6 +42,11 @@ export class JsonFormatter extends BaseFormatter { }; const rest = omit(record, ['hostname', 'level', 'msg', 'time', 'name']); + if (hasOwnProperty(rest, 'reqId') && hasOwnProperty(rest, 'req') && rest.req.id === null) { + rest.req.id = rest.reqId; + delete rest.reqId; + } + return ( JSON.stringify({ ...payload,