Winston logging object

前端 未结 5 1964
轻奢々
轻奢々 2021-02-13 12:23

I use Winston for my backend logging I cannot log the object without using JSON.stringify which is annoying

logger.debug(`Register ${JSON.stringify(         


        
5条回答
  •  孤街浪徒
    2021-02-13 13:03

    Or you just use the

    printf

    function in conjunction with JSON.stringify

    new winston.transports.Console({
      format: winston.format.combine(
        winston.format.colorize(),
        winston.format.simple(),
        winston.format.printf(context => {
          const msgstr = JSON.stringify(context.message, null, '\t')
          return `[${context.level}]${msgstr}`
        }),
      ),
    })
    

提交回复
热议问题