-
Notifications
You must be signed in to change notification settings - Fork 116
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
Fix #42 #43
Fix #42 #43
Conversation
I think this is going to be semver major. Custom Given this, I think it is best to:
That means |
2 similar comments
logger.js
Outdated
Object.defineProperty(_req, 'raw', { | ||
enumerable: false, | ||
value: req | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new property via defineProperty
in a serializer (which is a hot-path) is definitely not a good idea perf-wise. We should transform asReqValue
in a class, and attach this property to its prototype, and always memorize it internally through a Symbol
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the PR. I hope I have addressed your concern correctly.
Benchmarks for commit 5aebe40:
|
writable: true, | ||
value: '' | ||
}, | ||
raw: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at this point I fail to see the point of the symbol
@mcollina - thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gives a free non-enumerable. While writing this I learned:
const proto = Object.create({}, {
foo: {
enumerable: false,
writable: true,
value: {}
}
})
const instance = Object.create(proto)
console.log('%j', instance) // {}
instance.foo = 'foo'
console.log('%j', instance) // {"foo":"foo"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no sure – but you'd get that without the symbol and the getter/setter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats req.raw for btw... I saw it in the hapi-pino implementation as well - whats the reasoning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no no wait, you'd need a getter - but you could just return req
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, same thing happens with the getter and setter unless you wrap the object in a function with an enclosed variable to contain the value instead of set (val) { this._foo = val }
.
As for req.raw, see comments hapijs/hapi-pino#34 (comment) and hapijs/hapi-pino#34 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha!
@@ -303,3 +303,34 @@ test('does not crash when no request connection object', function (t) { | |||
res.end() | |||
} | |||
}) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test for raw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
2 similar comments
@mcollina @davidmarkclements opinions on #43 (comment)? Or is this PR not semver major? |
I agree on major for pino-http Even though I suggested removing serialisers from pino core I'm not sure I want to potentially break something someone is doing for the sake of purity |
We need to check that Koa integration works with this as well, should do - but worth a check |
I think we should bite the bullet and do the same thing for res as well, so that we can stop depending on the standard res serializers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM anyway
@mcollina same PR or a different one? |
@jsumners up to you :). Is this semver-minor or semver-major for you? If it's semver-major, then I would combine them in a single release. |
Both @davidmarkclements and I are of the opinion that this is semver-major. |
I would prefer to combine this with the change on |
@mcollina as you wish, it is done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :D Thanks!
edger-reqs branch:
master branch: