Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Replace reqId with req.id (if it is available)
Browse files Browse the repository at this point in the history
  • Loading branch information
auguwu committed Mar 12, 2023
1 parent cb4541f commit 2dcb670
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/formatters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down

0 comments on commit 2dcb670

Please sign in to comment.