Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Options<IM = IncomingMessage, SR = ServerResponse, CustomLevels
customLogLevel?: ((req: IM, res: SR, error?: Error) => pino.LevelWithSilent | CustomLevels) | undefined;
customReceivedMessage?: ((req: IM, res: SR) => string) | undefined;
customSuccessMessage?: ((req: IM, res: SR, responseTime: number) => string) | undefined;
customErrorMessage?: ((req: IM, res: SR, error: Error) => string) | undefined;
customErrorMessage?: ((req: IM, res: SR, error: Error, responseTime: number) => string) | undefined;
customReceivedObject?: ((req: IM, res: SR, val?: any) => any) | undefined;
customSuccessObject?: ((req: IM, res: SR, val: any) => any) | undefined;
customErrorObject?: ((req: IM, res: SR, error: Error, val: any) => any) | undefined;
Expand Down
5 changes: 4 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pinoHttp<CustomRequest, CustomResponse>({ customSuccessMessage: (req: CustomRequ
// #customErrorMessage
pinoHttp({ customErrorMessage: (req: IncomingMessage, res: ServerResponse, error: Error) => `Error - ${error}` });
Copy link
Contributor

@lokeshwar777 lokeshwar777 Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of overwriting the whole prop you could update the existing config (line 49) to include customErrorMessage with responseTime (avoids redundancy and looks clean) 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as suggested. Thanks 👍

pinoHttp<CustomRequest, CustomResponse>({ customErrorMessage: (req: CustomRequest, res: CustomResponse, error: Error) => `Error - ${error}` });
pinoHttp({
customErrorMessage: (req:IncomingMessage, res:ServerResponse, error:Error, responseTime:number) => `Error - ${error.message} after ${responseTime}ms`
});

// #customAttributeKeys
pinoHttp({ customAttributeKeys: { req: 'req' } });
Expand Down Expand Up @@ -150,7 +153,7 @@ const options: Options = {
return `Received HTTP ${req.httpVersion} ${req.method}`;
}),
customSuccessMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse) => 'successMessage'),
customErrorMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error) => 'errorMessage'),
customErrorMessage: canBeUndefined((req: IncomingMessage, res: ServerResponse, error: Error, responseTime: number) => 'errorMessage'),
customAttributeKeys: canBeUndefined(customAttributeKeys),
wrapSerializers: canBeUndefined(rtnBool()),
customProps: canBeUndefined((req: IncomingMessage, res: ServerResponse) => ({} as object)),
Expand Down