hg-pyun / axios-logger

Beautify Axios Logging Messages
MIT License
173 stars 33 forks source link

Why should we bind this to a custom logger? it should be the logger object itself right? #123

Open lokesh1729 opened 1 year ago

lokesh1729 commented 1 year ago

Hey,

To use a custom logger, I see the below line in the documentation

logger: logger.info.bind(this)

I am wondering about the value of "this" would vary depending on the context right? when I used setGlobalConfig function with Winston logger instance, this is passed as undefined to DerivedLogger.

Winston is setting this to DerviedLogger instance if it is undefined - https://github.com/winstonjs/winston/blob/master/lib/winston/create-logger.js#L73

So, It should be logger.info.bind(logger) instead of this right? can you please explain why we should use this? Are we sure that this will be undefined every time?