首页 > 解决方案 > Winston createLogger 自定义函数

问题描述

在我的节点应用程序中,我使用 winston 进行错误记录。我想在一个地方创建一个函数并在 server.js 文件中使用它。这是我的文件

const exceptionLogger = () => {
  createLogger({
    exceptionHandlers: [
      new transports.File({ filename: 'exceptions.log' }),
    ],
  });
};

但是这个函数不能被称为exceptionLogger()。它使应用程序崩溃。这是什么原因?我怎样才能以正确的方式做到这一点?

标签: javascriptnode.jswinston

解决方案


你可以试试这个:

export const exceptionLogger = () => {
  winston.createLogger({
    exceptionHandlers: [
      new winston.transports.File({ filename: 'exceptions.log' }),
    ],
  });
};

推荐阅读