如何自定义Winston输出

时间:2019-02-28 09:57:57

标签: javascript node.js winston

我想制作一个自定义的Winston记录器输出,我使用的是Winston ^ 3.2.1,我想同时在控制台和文件中输出日志,这是我想要得到的:{timestamp-API_URL -{param1}-{param2}}

这是我的代码:

const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const config = require("./");
const myFormat = printf(({ level, message, label, timestamp }) => {
  return `${timestamp} [${label}] ${level}: ${message}`;
});
console.log(myFormat);
const logger = createLogger({
 format: combine(
  label({ label: 'right meow!' }),
  timestamp(),
  myFormat
),
 transports: [new transports.Console(),
   new transports.File({
    filename: logger.log,
    level: 'info'
  })
 ]
 });
module.exports = logger;

有什么帮助吗?

0 个答案:

没有答案