ðŸ˜** Knex JS breaks logger**
Knex is one of the most well-known libraries for working with SQL in NodeJS. And as expected, libraries of this kind can accept an external logger as input.
BUT instead of simply calling the logger's functions, it overrides all its methods in its own class (photo 1)...
Have you guessed what the problem might be? Answer in 3... 2... 1...
And the problem is that if your logger uses "this" without binding it to an instance (which is not mandatory), then its "this" will now refer to Knex's internal logger class...
In my recent projects, I often use the Pino logger, and inside its logic, "this" is used without binding, which leads to a crash of the application.
To make everything work, I have to use a nasty hack (photo 2).
What does this teach us?
"This" is a very sneaky thing, and of course, I want to say "just stop using class notation" (because I haven't used it for a long time), but in reality, I ask you to at least not override methods of another (especially uncontrollable) object.
Powerful leveling up to you 💪