toajs / toa-logging

HTTP request logging middleware for Toa.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toa-logging

HTTP request logging middleware for Toa.

NPM version Build Status Downloads

Example

simple toa server

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)

API

const logging = require('toa-logging')

logging([options])

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.

options.skipper

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 === '/'
  }
})

options.init

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~

options.consume

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
}

Licences

(The MIT License)

About

HTTP request logging middleware for Toa.

License:MIT License


Languages

Language:JavaScript 100.0%