Discussion on: What JS Logging library / tool do you use?

mattdevio profile image
Matt G

On the front end, I mainly use console.log; however, I turn the logging on and off via an environment variable before I compile. If the logging is turned off, the log function does a no op.

const logFunc = (process.env.NODE_ENV === 'development') ? console.log : () => {};

class Utility {

     static log(...args) {
           // Usually I do some normalization and enhancement here by map over the args
           const enhancedArgs = args.map(arg => JSON.stringify(arg, null, 2))

           // Call the logFunc with console
           logFunc.apply(console, enhancedArgs)

Enter fullscreen mode Exit fullscreen mode

On the server side, I use winston and morgan.