-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
self._addDefaultMeta is not a function error still occurs with 3.2.1 #1591
Comments
Could you please provide reproduction code? Ideally a complete test that fails, e. g. based on https://github.com/winstonjs/winston/blob/master/test/logger.test.js |
Yeah, I was going to try to narrow it down and follow up with that, but wanted to raise the issue as fast as possible in case someone could figure it out :) |
Seems to boil down to: const winston = require('winston');
const logger = winston.createLogger({
transports: [
new winston.transports.Console()
]
});
const logHelper = {
log: logger.info
};
logHelper.log('Hello'); Works in 3.1.0, but fails in 3.2.1 with:
It feels like a misuse of the API as it's not really fair game to pick out a method and call it on another object. Still, it used to work, so gray area :) |
Thanks for reporting this bug, but yes: the failure is by design. If you would like to create another object with it's own properties that is still a logger, use |
Another way I found that works is to bind: const logHelper = {
log: logger.info.bind(logger)
}; |
@indexzero I dont understand how I can create a log helper like wished for here with the sentence you provided? |
`const winston = require('winston'); const logger = winston.createLogger({ const logHelper = { module.exports.log = { };` |
So this logger.info.bind(logger) works for me. But I cannot say why. |
Binding somehow solved my issues with maximum call stack. Would love a good explanation on why this works or an actual solution... but thanks! |
@ionizer me too, just didnt get the stackoverflow posted earlier. maybe @indexzero can chime in? |
@vongohren I think I get it now, though it's a bit hard for me to explain. In some cases where we wrap the logger in an object like so: const logHelper = {
log: logger.info
}; ...the The exact explanation according to the SO answer is that outside the EDIT: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind |
@ionizer ah ok! Did not now the context inside the object dissapeard |
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: 11.6.0What is the problem?
Seems like #1579 did not fully fix the
_addDefaultMeta
bug. After upgrading to winston 3.2.1 I still get this error in my app atwinston/lib/winston/create-logger.js
Line 80 in efd7baf
Full stack trace:
What do you expect to happen instead?
That my app does not crash with the above error
The text was updated successfully, but these errors were encountered: