Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Latest commit

 

History

History
82 lines (57 loc) · 1.83 KB

README.md

File metadata and controls

82 lines (57 loc) · 1.83 KB

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)