Webhook 日志查询

问题描述 投票:0回答:1

所以我有这个测试 webhook 设置来捕获一些事件,如何添加日志记录以便将所有输出保存到文件中并保存每日日志?

const express = require('express');
const bodyParser = require('body-parser');
 
const app = express();
app.use(bodyParser.json());
 
app.get('/', (req, res) => {
    res.send('Webhook server is running');
});
 
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
    console.log(`Webhook server is listening on port ${PORT}`);
});
 
app.post('/webhook', (req, res) => {
    console.log('Webhook event received:', req.body);
    res.status(200).send('OK');
});
app.post('/event', function (req, res) {
  var events = req.body;
  events.forEach(function (event) {
    
      processEvent(event);
  });
});

尝试启用日志记录?

node.js webhooks
1个回答
0
投票

如果你要使用

morgan
,它会是这样的

app.use(morgan('common', {stream: fs.createWriteStream('./webhook.log', {flags: 'a'})}));
© www.soinside.com 2019 - 2024. All rights reserved.