我對使用express-bunyan-logger的問題做了short, self contained example。使用express-bunyan-logger和graphql記錄查詢字符串
我試圖添加express-bunyan-logger作爲中間件,並利用includesFn
將查詢字符串和正文記錄爲自定義字段。
const app = express();
const graphqlLogger = require('express-bunyan-logger')({
name: 'graphql-logger',
includesFn: (req, res) => {
const includes = {};
if (req.body) includes.req_body = JSON.stringify(req.body);
if (req.query) includes.req_query = JSON.stringify(req.query);
return includes;
},
});
app.use(graphqlLogger);
問題是,即使是形式http://localhost:4000/graphql?query=query%20%7B%0A%20%20books%20%7B%0A%20%20%20%20title%0A%20%20%7D%0A%7D的URL,該req_query
和req_body
領域始終是空的。如果我檢查在調試器中傳遞給includesFn
的req
對象,它不包含req.query或req.params的任何值。
我確定我在這裏做錯了事;如何讓includesFn
正確記錄查詢字符串和正文?