-
Notifications
You must be signed in to change notification settings - Fork 865
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
add bindings
method to logger instances
#588
Conversation
Register a symbol for the method Reference the method in prototype
As you suggested @mcollina I created the PR early. I have anyway no choice, I'm stocked :( I tried to expose the method on every logger but I'm obviously overseeing something, this is what the tests tell me. And I'm still not happy about the naming, "chindings" are used already in prototype.child() to store the result as string. |
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.
just some initial feedback
Rename the method for child bindings
I verified and you are absolutely right, the childBindings is available. Unfortunately it does not return the expected chindings because the stream.lastLogger does not exists at that point. function childBindings () {
const chindings = this[chindingsSym]
var chindingsObject = (chindings.indexOf(',') === 0) ? `{${chindings.substr(1)}}` : `{${chindings}}`
var bindings = JSON.parse(chindingsObject) || {}
// eventually strip props as hostname and pid
return bindings
} What do you think? |
+1 to that proposal @yellowbrickc! I would add that we should cache that value as it's not going to change after usage. I like it a lot for two reasons:
|
Ok, than I will do this. var bindings = null
function childBindings () {
if (!bindings) {
const chindings = this[chindingsSym]
var chindingsObject = (chindings.indexOf(',') === 0) ? `{${chindings.substr(1)}}` : `{${chindings}}`
bindings = JSON.parse(chindingsObject) || {}
// eventually strip props as hostname and pid
}
return bindings
} will the second of these tests fail, the method still returns the object w/o {foo: 'bar'} test('WIP childBindings are exposed on instance', async ({ isA }) => {
const instance = pino()
isA(instance.childBindings(), 'object')
})
test('WIP childBindings are exposed on every instance', async ({ match }) => {
const instance = pino().child({ foo: 'bar' })
match(instance.childBindings(), { foo: 'bar' })
}) |
Let's leave caching to a later time :). |
Quick check though: would a user expect the bindings to be cloned, or would a user expect to have the same object that was passed to child (referntially)? |
100% cloned. |
Given an input API: I kind of would expect the same object back, however we definitely should clone it because we need to uphold/promote the assumption that once set, the bindings are immutable. So we'll need to make docs clear on this. @yellowbrickc if it makes sense to clone directly from the passed in |
Expose it in the prototype. Extend the docs.
Sorry, I didn't see your last comments. I tried but I cannot imagine any situation where I would need something else from a childlogger. But it is your decision :) |
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.
nice job so far!
I think this also has to be intergrated with pretty wrapper as well right? we need to remove that code from the pretty wrapper and use this instead? |
The private method in the prettyWrapper does not remove any props, adds "v:1" to the output and is based on the lastLogger which is created/overwritten during the life cycle of the logger instance. It is used only for writing the logs. |
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.
Good work!
Co-Authored-By: yellowbrickc <yellowbrickc@users.noreply.github.com>
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
Finally I passed your 100% code coverage requirement 😆 |
Thanks for keeping up with us @yellowbrickc! Good work! |
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
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
sorry for the delay, I'm just thinking about the name, if the logger is a child, then the returned object isn't child bindings, it's just bindings I think we should rename |
Done. |
amazing thanks @yellowbrickc |
bindings
method to logger instances
v5.11.0 released 👍 |
It was a pleasure.
|
I suspect some of the back and forth was due to a small language barrier. Regardless if that is true or not, it’s not the ultimate delta in code size that dictates the conversation around its implementation. The goal of the conversation is to make sure the right code gets checked in. |
I have no problem at all with back and forth communication. I rather build something what fulfills some needs than something else. This is why I liked the last change request from @davidmarkclements very much because it shows that you really care not only about coding but also about naming. Maybe I can give my answers:
BTW: thank you for the "fireworks" on twitter, I was really flattered - because we know that it wasn't that much what I did. |
Pino does not receive many contributions, and this was exceptionally well done. |
## The dependency [pino](https://github.com/pinojs/pino) was updated from `5.10.10` to `5.11.0`. This version is **not covered** by your **current version range**. If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update. --- <details> <summary>Release Notes for v5.11.0</summary> <ul> <li>add <code>bindings</code> method to logger instances <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="401113555" data-permission-text="Issue title is private" data-url="pinojs/pino#588" data-hovercard-type="pull_request" data-hovercard-url="/pinojs/pino/pull/588/hovercard" href="https://urls.greenkeeper.io/pinojs/pino/pull/588">#588</a></li> </ul> </details> <details> <summary>Commits</summary> <p>The new version differs by 12 commits.</p> <ul> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/fd96fd983432338f52a3811ce928a52321f23400"><code>fd96fd9</code></a> <code>5.11.0</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/e2ec9ff02937b99d4276ad145c51125bde847555"><code>e2ec9ff</code></a> <code>Merge pull request #588 from yellowbrickc/issue-560</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/694da028230b8c2a3a3f223843bb4d855ba654ac"><code>694da02</code></a> <code>Rename childBindings to bindings.</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/5c8834f3a0fe0627456e5955176fb18d7bae8285"><code>5c8834f</code></a> <code>Remove unnecessary security net, cannot happen.</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/e17d319d31a33b4027101d6c6f3efd1bb030d944"><code>e17d319</code></a> <code>Remove try-catch (cannot be tested), even the logger is minimal configured, the method works.</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/b90ac8f17062c364221a9bb3a6efcbe742203587"><code>b90ac8f</code></a> <code>Small refactoring</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/e952417b15c5c673876f29449fcca7d09906fcc7"><code>e952417</code></a> <code>Update docs/api.md, logger.childBindings</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/52ae8cac8e07cd2046dca2383cdcab62fee7e3d3"><code>52ae8ca</code></a> <code>Create a method to retrieve all current bindings.</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/1246ac49089fa3fcc07fbde64ff902b43dfa7c79"><code>1246ac4</code></a> <code>Revert "Remove the new symbol and the reference Rename the method for child bindings"</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/ede794c3ff0fa018c339e0891278e75570ed67ce"><code>ede794c</code></a> <code>Revert "Remove the new symbol and the reference Rename the method for child bindings"</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/1569e4654854191f1986217f727fed7f2779b2e3"><code>1569e46</code></a> <code>Remove the new symbol and the reference</code></li> <li><a href="https://urls.greenkeeper.io/pinojs/pino/commit/d8e9847c384b5075ec2e6904191e6b349220d95d"><code>d8e9847</code></a> <code>Expose tools.getChindings()</code></li> </ul> <p>See the <a href="https://urls.greenkeeper.io/pinojs/pino/compare/2ba03f244021aed566b9f95b8cca2509bcdd2464...fd96fd983432338f52a3811ce928a52321f23400">full diff</a></p> </details> <details> <summary>FAQ and help</summary> There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new). </details> --- Your [Greenkeeper](https://greenkeeper.io) bot 🌴
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Step 1:
Expose tools.getChindings()
Register a symbol for the method
Reference the method in prototype.