express-zod-api: Customising logger with winston erroring out in v19
Description
Following the instructions in the README for customising the logger for winston, I encounter an error on calling the child method on parent in the method passed to childLoggerProvider.
Here is the error that I receive:
➜ project git:(main) pnpm run start
> project@1.0.0 start /Users/sourabh/Experiments/project
> tsx index.ts
2024-05-16T16:28:29.251Z info: Listening 8090
/Users/sourabh/Experiments/project/config.ts:21
return parent.child({ requestId: Math.random() * 100000 });
^
TypeError: parent.child is not a function
at Object.childLoggerProvider (/Users/sourabh/Experiments/project/config.ts:21:23)
at <anonymous> (/Users/sourabh/Experiments/project/node_modules/.pnpm/express-zod-api@19.1.1_express@4.19.2_http-errors@2.0.0_typescript@5.4.5_zod@3.23.8/node_modules/express-zod-api/dist/index.js:5:10350)
at Layer.handle [as handle_request] (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:328:13)
at /Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:346:12)
at next (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:280:10)
at expressInit (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/middleware/init.js:40:5)
at Layer.handle [as handle_request] (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/sourabh/Experiments/project/node_modules/.pnpm/express@4.19.2/node_modules/express/lib/router/index.js:328:13)
Node.js v20.12.2
ELIFECYCLE Command failed with exit code 1.
However the logger works when you directly return logger.child() instead of parent.child().
Expected
Should be able to return using the parent.child() as specified in the README, worked as expected in v18
Reproduction
Here’s a sample repo https://github.com/boarush/winston-eza-example. Try using the /status endpoint when returning the parent.child() and logger.child().Former errors and latter works.
Context
- Node.js version: 20.12.2
express-zod-apiversion: 19.1.1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
Commits related to this issue
- Logger instance recognition failure (#1773) Fixes #1772 — committed to RobinTail/express-zod-api by RobinTail 3 years ago
- Backport of #1773 8670f90 that fixes #1772 that may occur in v18. — committed to RobinTail/express-zod-api by RobinTail 3 years ago
- Backport of #1773 for v18 (#1774) Backport of #1773 that fixes #1772 that may occur in v18. — committed to RobinTail/express-zod-api by RobinTail 3 years ago
Yep, it works, thanks a lot again!
@boarush , configuring winston is not easy, so I moved from it. But you can check out how it was configured in v17 for inspiration
https://github.com/RobinTail/express-zod-api/blob/a6ae0640259f53814e330d3ddd52a556b28e22a2/src/logger.ts#L98-L110
You need to set both
levelsandlevel. Last one acts as a filter (ignores what’s below it), @boarushThanks for the speedy fix!
🚀 Should be fixed in v19.1.2 , @boarush I tested it on your repo. Thank you once again for your contribution! I highly appreciate it.
@RobinTail I had also been using it in production with Winston specifically with v18. Didn’t really face any issue or crashes.
I think you misunderstood me, I am agreeing with what you suggested.
No-no, it does not interfere in their operation. It’s just a check of the object shape.
Need to check prototype in
isBuiltinLoggerConfig.Confirmed, @boarush Thank you for reporting this.