HTTP request logging middleware for Toa.
const Toa = require('toa')
const logging = require('toa-logging')
const app = new Toa()
app.use(logging())
app.use(function () {
// logging middleware will add a Log instance to context.state
this.body = this.state.log
})
app.listen(3000)
const logging = require('toa-logging')
Create a new logging middleware function with options
. logging middleware will add a Log instance to context.state
, you can append key/value to the log like this.state.log.someKey = someValue
.
Function to determine if logging is skipped, defaults to false
. This function
will be called as skipper.call(context)
.
logging({
skipper: function () {
return this.path === '/'
}
})
Set a init function that will run at the begin. This function
will be called as init.call(context, context.state.log)
. Default to:
function defaultInit (log) {} // do nothing~
Set a consume function that will run at the end. This function
will be called as consume.call(context, context.state.log)
. Default to:
function defaultConsume (log) {
log.status = this.status
ilog.info(log) // write the log by ilog.info
}
(The MIT License)