Skip to content

QubitProducts/koa-driftwood

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-driftwood

A tiny piece of express middleware for logging requests using QubitProducts/driftwood.

Installation

npm i driftwood koa-driftwood

Usage

Just call koa-driftwood with an instance of driftwood and mount it in your Koa app before everything else:

const createLogger = require('driftwood')
const Koa = require('koa')
const router = require('koa-router')()
const koaLogger = require('koa-driftwood')

createLogger.enable({ '*': 'trace' })

const log = createLogger('my-app')
const app = new Koa()

app.use(koaLogger(log))

router.get('/', (ctx) => { res.body = 'Wooo!' })
router.get('/400', (ctx) => { ctx.status = 400; ctx.body = 'You dun goofed' })
router.get('/500', (ctx) => { ctx.status = 500; ctx.body = 'We dun goofed' })

app.use(router.routes())

app.listen(1119, () => {
  log.info('my-app started!')
})

Options

Options can be passed as a second argument.

options.ignore

A string, regex, function or array of the former, to match URLs that you don't want to log:

{
  ignore: ['/status', /^\/status/, (url) => url.indexOf('/status') > -1]
}

Releases

No releases published

Packages

No packages published