Skip to content

fix: assign log levels to un bound functions#1483

Merged
DABH merged 3 commits into
winstonjs:masterfrom
soldair:patch-1
Sep 26, 2018
Merged

fix: assign log levels to un bound functions#1483
DABH merged 3 commits into
winstonjs:masterfrom
soldair:patch-1

Conversation

@soldair
Copy link
Copy Markdown
Contributor

@soldair soldair commented Sep 26, 2018

binding custom log level functions to this with arrow functions causes unintentional behavior.
the expectation is that they should be callable the same way as logger.log

if you extend a logger instance logger.log will be called with logger being this whereas logger.warn can only be called with logger.prototype as this.

this fixes #1482 but I believe it should be treated as a bug. I doubt blocking extension of only part of the surface area of the logger instance was intended.

this sets the base for efficient child loggers that only extend write to add attributes.

attn @DABH

//todo tests =)

binding custom log level functions to `this` with arrow functions causes unintentional behavior. 
the expectation is that they should be callable the same way as logger.log

if you extend a logger instance `logger.log` will be called on `logger` whereas `logger.warn` will be called on `logger.prototype` 

this fixes winstonjs#1482 but I believe it should be treated as a bug. I doubt blocking extension of only part of the surface area of the instance was intended. 

this sets the base for efficient child loggers that only extend write to add attributes.
@DABH
Copy link
Copy Markdown
Contributor

DABH commented Sep 26, 2018

This was probably an unintended side-effect of rewriting all our code in ES6. So good catch! :)

If you could add probably just one test to show what wasn't working before (and prevent regressions), I'd be happy to merge this in. Thanks for your contribution!

Copy link
Copy Markdown
Member

@indexzero indexzero left a comment

Choose a reason for hiding this comment

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

@soldair if it is possible to add a unit test to cover it would be very helpful to avoid this kind of regression in the future.

Thanks for the contribution 🎉

@soldair
Copy link
Copy Markdown
Contributor Author

soldair commented Sep 26, 2018

this test tests the shape of logged messages more than it has to. I only really need to check that the length of logged messages is 2.

Please let me know if you'ed prefer i update it. I'm happy to.

@DABH
Copy link
Copy Markdown
Contributor

DABH commented Sep 26, 2018

LGTM once CI passes! Thanks again.

@ofrobots
Copy link
Copy Markdown
Contributor

ofrobots commented Oct 4, 2018

Would it be possible to get this fix in a release?

@DABH
Copy link
Copy Markdown
Contributor

DABH commented Oct 4, 2018

Probably will get a release cut on Friday!

@ofrobots
Copy link
Copy Markdown
Contributor

Gentle reminder for a release 😀

@ofrobots
Copy link
Copy Markdown
Contributor

@DABH @indexzero could we get this, or #1471 in a release?

@DABH
Copy link
Copy Markdown
Contributor

DABH commented Dec 13, 2018

@ofrobots Yep, plan is to release both on 12/23 if no surprises come up. Sorry for delays -- schedule/life conflicts prevented maintainer meetings from happening in Oct/Nov. Thanks for bearing with us.

Mizumaki pushed a commit to Mizumaki/winston that referenced this pull request Jun 11, 2020
* fix: assign log levels to un bound functions 

binding custom log level functions to `this` with arrow functions causes unintentional behavior. 
the expectation is that they should be callable the same way as logger.log

if you extend a logger instance `logger.log` will be called on `logger` whereas `logger.warn` will be called on `logger.prototype` 

this fixes winstonjs#1482 but I believe it should be treated as a bug. I doubt blocking extension of only part of the surface area of the instance was intended. 

this sets the base for efficient child loggers that only extend write to add attributes.

* test: test for custom method prototype binding

* style
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

Successfully merging this pull request may close these issues.

Ability to create namespaced child loggers

4 participants