Skip to content

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

@lokesh1729

Description

@lokesh1729

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions