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

self.log not a function #1648

Open
1 of 2 tasks
jaumard opened this issue May 22, 2019 · 3 comments
Open
1 of 2 tasks

self.log not a function #1648

jaumard opened this issue May 22, 2019 · 3 comments

Comments

@jaumard
Copy link

jaumard commented May 22, 2019

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • _node -v outputs: v10.15.3
  • _Operating System: macOS
  • _Language: ES6/7

What is the problem?

Previously with winston@2 I was doing like this: log.debug.apply(this, ['lisa-plugin-hue', 'preferences', {}]) but now with the v3 it gave me this:

TypeError: self.log is not a function
    at Object.DerivedLogger.(anonymous function) (/Users/jaumard/IdeaProjects/lisa-box/node_modules/winston/lib/winston/create-logger.js:95:19)
    at Object.<anonymous> (/Users/jaumard/IdeaProjects/lisa-box/test.js:15:11)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Here is how to reproduce:

const winston = require('winston')

const log = winston.createLogger({
  level: 'debug',
  exitOnError: true,
  transports: [
    new (winston.transports.Console)({
      prettyPrint: true,
      colorize: true
    })
  ]
})

log.debug.apply(this, ['lisa-plugin-hue', 'preferences', {}])

What do you expect to happen instead?

Have the log and no crash :)

Other information

Maybe I need to adapt my code now if it doesn't work the same way as v2 ?

@EricRabil
Copy link

Logger functions aren't bound to the logger object, so in that example you would need to change log.debug.apply(this, ...) to log.debug.apply(log, ...) so that the function is executed with the correct this or self variable.

@stonebinox
Copy link

This isn't fixed yet? Can't use the workaround when another library invokes it.

@wbt
Copy link
Contributor

wbt commented May 18, 2023

#FundOpenSource

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

4 participants