koa-driftwood
v1.0.1
Published
Koa middleware for logging with driftwood
Downloads
2
Readme
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]
}