Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not best practice to bind to Node request and response object? #14

Open
niftylettuce opened this issue Jan 9, 2019 · 12 comments
Open

Comments

@niftylettuce
Copy link

I think that it'd be best practice to not bind to the Node request/response object and instead just solely bind to the Koa request and response object.

https://github.com/pinojs/koa-pino-logger/blob/master/logger.js#L11

-ctx.log = ctx.request.log = ctx.response.log = ctx.req.log
+ctx.log = ctx.request.log = ctx.response.log;

Also not having ctx.res.log to begin with is kind of odd since you're binding to ctx.response.log and ctx.req.log, should be a 1:1 relationship.

@niftylettuce
Copy link
Author

if you're open to this I will submit PR to fix, would require a major version bump and also a deprecation notice IMO

@davidmarkclements
Copy link
Member

Yeah I’m ok with that -
@mcollina @jsumners ?

@mcollina
Copy link
Member

mcollina commented Jan 9, 2019

I'm +1, that should be a semver-major change.

@jsumners
Copy link
Member

jsumners commented Jan 9, 2019

I know nothing of Koa. Do whatever is best.

@niftylettuce
Copy link
Author

Thanks, I'll make a PR now! Also feel free to add me to NPM and GitHub so I can help maintain this package. I use it directly in CabinJS https://cabinjs.com and Lad https://lad.js.org.

@niftylettuce
Copy link
Author

Actually it looks like pino-http is the culprit as to why this issue exists to begin with - specifically https://github.com/pinojs/pino-http/blob/f8236514c514a85885701cd82667a4b1fbc48a8a/logger.js#L62 sets req.log, which in this context we can't workaround unless we have an ugly delete ctx.req.log afterwards.

The reason we need to pass the Node request and response object to pino-http's wrapping is because of this https://github.com/pinojs/pino-http/blob/master/logger.js#L66-L67 (event listeners on Node's request object).

Any thoughts as to what we can do here?

@mcollina
Copy link
Member

mcollina commented Jan 9, 2019

I think we should follow the same approach we do in hapi-pino, mainly building a custom module for Koa. Would that make sense? Would you like to send a PR?

@stephanebachelier
Copy link

@mcollina are you still interested in building a custom module for Koa ? There are some limitations apart from the fact that this module is only a thin wrapper around pino-http.

@mcollina
Copy link
Member

mcollina commented Jan 4, 2021

It'd be great if somebody contributed a PR :).

@stephanebachelier
Copy link

@mcollina ok I'm in.

@jmealo
Copy link
Contributor

jmealo commented Mar 9, 2021

@stephanebachelier: Where did you end up with this? I've built out a fair bit of log enrichment outside of process that I'd like to get rid of.

@jmealo
Copy link
Contributor

jmealo commented Mar 9, 2021

@stephanebachelier: @mcollina: #31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants