【发布时间】:2020-10-25 14:27:57
【问题描述】:
我正在尝试将 DataDog 与我的 NodeJS/Express 应用程序集成,但是当一个 POST 请求被发送到我的应用程序时,POST 的主体没有被传递给 datadog,我该如何解决这个问题?
我有一个名为 Winston.js 的文件,如下所示:
let appRoot = require('app-root-path');
let winston = require('winston');
// define the custom settings for each transport (file, console)
let options = {
file: {
level: 'info',
filename: `${appRoot}/logs/app.log`,
handleExceptions: true,
json: true,
maxsize: 52428800,
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
},
};
// instantiate a new Winston Logger with the settings defined above
let logger = winston.createLogger({
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console)
],
exitOnError: false, // do not exit on handled exceptions
});
// create a stream object with a 'write' function that will be used by `morgan`
logger.stream = {
write: function(message, encoding) {
// use the 'info' log level so the output will be picked up by both transports (file and console)
logger.info(message);
},
};
module.exports = logger;
然后我使用以下方法将它们附加到我的应用程序中:
app.use(morgan('combined', { stream: winston.stream }));
【问题讨论】: