L
L
LinuxGod2022-02-18 23:03:16
Node.js
LinuxGod, 2022-02-18 23:03:16

How to remap console.log function in nodejs?

Good afternoon, colleagues.
I ran into such a difficulty, there is a very good library provided by the npm package for outputting trees, tables and other things (ascii) to the console, but unfortunately the logger that displays debug information about the server state cannot pull them up, since apparently inside this same library uses console.log.

My task is to reassign console.log to a method for outputting normal server logs with debugging information, etc.

In the code, it really is reassigned like this: But for some reason npm packages do not suck it in and continue to output everything in the usual console.log.
console.log = (message) => logger.info(message)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2022-02-19
@Aetae

Take out your substitution in a separate module and make it require\import BEFORE importing that library.
True, it's not a fact that either uses console.log, and not stdout directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question