我刚开始使用 Node,现在我想向我的应用程序添加一些日志记录,为此 Winstonjs似乎很合适。所以我首先安装了它:
npm install winston
然后我从自述文件中复制了第一个示例代码(并在它之前添加了要求):
"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
有人知道我在这里做错了什么吗?欢迎所有提示!
最佳答案
关于javascript - 使用 Winstonjs 记录器进行 Node 记录会出现 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949067/