用Winstonjslogging器logging节点给TypeError
我刚刚开始与节点,我现在想要添加一些日志到我的应用程序,为此Winstonjs似乎是一个完美的契合。 所以我第一次安装它:
npm install winston
然后我复制自述文件中的第一个示例代码(并在之前添加了require):
"use strict"; let winston = require('winston'); const logger = winston.createLogger({ level: 'info', format: winston.format.json(), transports: [ // // - Write to all logs with level `info` and below to `combined.log` // - Write all logs error (and below) to `error.log`. // new winston.transports.File({ filename: 'error.log', level: 'error' }), new winston.transports.File({ filename: 'combined.log' }) ] }); // // If we're not in production then log to the `console` with the format: // `${info.level}: ${info.message} JSON.stringify({ ...rest }) ` // if (process.env.NODE_ENV !== 'production') { logger.add(new winston.transports.Console({ format: winston.format.simple() })); }
但是我得到一个错误:
/Users/kramer65/mms/testlogging.js:7 format: winston.format.json(), ^ TypeError: Cannot read property 'json' of undefined
有人知道我在做什么错吗? 所有的提示,欢迎!
您的代码与尚未发布的新v3兼容。 如果你想安装它: npm i winston@next --save
或者如果你想坚持使用v2,你可以阅读npm上的v2文档
REF
- 将多个AngularJS Post请求发送到Express服务器? 服务器崩溃的第二个post请求
- 为什么async在循环中的node.js中给出错误
- Hubot启动时自动加载.env
- 在html中replaceurl无效
- TypeError:undefined不是node.js / express.js中的函数
- 如何在将图像上传到服务器时传递多个值(使用AngularJS和NodeJS进行file upload)?
- 多个mongoose count()查询到MongoDB
- 每5分钟安排一次工作
- 从node.js中获取错误Uncaught ReferenceError:模块未定义,未捕获ReferenceError:require未定义