Enable Pino Logging at a Particular Level

168 Views Asked by At

From researching the web, the proper way to enable logging at a certain level is by adding the 'level' attribute to the object passed into the pino constructor. The documentation can be found here.

However, per my logging configuration logger_config.js

import pino from "pino";

const send = function (level, logEvent, a, b) {}; 

const logger = pino({
   level: "trace",
   browser: {
      serialize: true,
      asObject: true,
      transmit: {
         send,
      },  
   },  
});

export default logger;

and logging usage, which contains a second way to set the level,

import logger from "../../logger_config";

export const myComponent = async (formData) => {
   logger.level = "trace";
   logger.error("ERROR");
   logger.info("INFO");
   logger.debug("DEBUG");

I was expecting the debug statement to print. Only the error and info level statements are printed. Furthermore, if I add a trace level debug statement, it gets printed, along with info and error; however, there is still no debug statement.

What's even more odd is that when the level is set to debug, "logger level is debug" from the following statement gets printed.

   if (logger.levelVal === 20) {
      console.log("logger level is `debug`");
   }   

I've restarted node after changing the level setting.

How do I get the debug statement to print (i.e. have everything at the debug level and above to print)?

0

There are 0 best solutions below