Sometimes you may need to integrate debug with a high performance logger, such as pino. And of course, there is an NPM package for that.

However, if you look at its source code, you will find out that it uses undocumented dirty hacks, which, in my opinion, make it quite fragile.

When I looked at its source code, I asked myself if it were possible to make it simpler. And the answer is yes — this is possible at least since debug 1.0.0 (that is, June 2014).

debug exports log() method, which performs — surprise! — logging. And — surprise! — it is possible to override it.

So,

Depending on your environment, you may want to disable colors: dbg.inspectOpts.colors = false; (this will work for debug >= 2)

This simple example does not handle the opts.map feature of pino-debug, yet it is very easy to implement. log() function receives the following object as its this object:

All properties in the object above are informative: they merely tell which settings were used to create the message log() function is about to log.

And there is no need to apply weird hacks to make debug and pino work together 🙂

Easy Way to Make pino and debug Work Together
Tagged on:                     

Leave a Reply

Your email address will not be published. Required fields are marked *