我试图在node.js中安装最新的Winston版本,但没有创建日志文件。但是旧版本创建了日志文件。如何在最新版本的代码中实现此功能?
winston.js
/**
* @fileoverview Winston Logging Configuration file.
*/
// Import Modules
const winston = require('winston');
require('winston-mongodb');
require('express-async-errors');
/**
* Function used to configure logging for the app.
* @param {Function} app - top-level function Express funtion.
* @returns {void} - none.
*/
const winstonLogging = function () {
// Uncaught Exceptions and UnchandledRejections
winston.handleExceptions(
new winston.transports.Console({ colorize: true, prettyPrint: true }),
new winston.transports.File({ filename: 'uncaughtExceptions.log' }));
process.on('unhandledRejection', (ex) => {
throw ex;
});
// Winston Configuration
winston.add(new winston.transports.File({ filename: 'logfile.log' }));
winston.add(new winston.transports.MongoDB({
db: 'mongodb://olcadmin:olcmongodb@127.0.0.1:27017/local?authMechanism=SCRAM-SHA-1&authSource=admin',
level: 'info'
}));
}
module.exports = winstonLogging;
旧版本
"winston": "^2.4.0"
Its working fine and sucessfully created log file
新版本
"winston": "^3.2.1"
Its not created log file
我遇到错误
[winston] Attempt to write logs with no transports {"message":"Server Started and Listening on port 5200","level":"info"}