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

toajs/toa-logging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published