nodeJS: v14.17.0
express-async-errors: "3.1.1",
mongoose: "5.13.7",
winston: "3.3.3",
winston-mongodb: "5.0.7"
config: "3.3.6"
代码:
const winston = require("winston");
const config = require("config");
require("winston-mongodb");
require("express-async-errors");
module.exports = function () {
db = config.get("db");
winston.exceptions.handle(
new winston.transports.Console({ colorize: true, prettyPrint: true }),
new winston.transports.File({ filename: "logs/uncaughtExceptions.log" })
);
process.on("unhandledRejection", (ex) => {
throw ex;
});
winston.add(new winston.transports.File({ filename: "logs/logfile.log" }));
winston.add(
new winston.transports.MongoDB({
db: db,
options: {
useUnifiedTopology: true,
},
})
);
};