它不是內置的,但很容易配置。您可以使用express-winston並添加到快速中間件堆棧。morgan
does not let you log the request body但expressWinston的作用:在CoffeeScript的
expressWinston.requestWhitelist.push('body');
expressWinston.responseWhitelist.push('body');
實施例:[?快遞JS到一個輸出文件中記錄]的
expressWinston.requestWhitelist.push('body')
expressWinston.responseWhitelist.push('body')
app.use(expressWinston.logger({
transports: [
new winston.transports.Console({
json: true,
colorize: true
})
],
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting, with the same colors. Enabling this will override any msg and colorStatus if true. Will only output colors on transports with colorize set to true
colorStatus: true, // Color the status code, using the Express/morgan color palette (default green, 3XX cyan, 4XX yellow, 5XX red). Will not be recognized if expressFormat is true
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
}));
可能重複(http://stackoverflow.com/questions/5489815/登錄到express-js-to-a-output-file) – thgaskell
它的確如此。你必須啓用它。查看thgaskell發佈的問題的答案。 – user568109