Skip to content

koa-modules/morgan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-morgan

HTTP request logger middleware for koa.
morgan wrapper for koa's middleware.

NPM version NPM Downloads Build status Test coverage Dependency status License

Install

$ npm install --save koa-morgan

Usage

=1.x, 100%, working with morgan and koa-v2

const fs = require('fs')
const Koa = require('koa')
const morgan = require('koa-morgan')

// create a write stream (in append mode)
const accessLogStream = fs.createWriteStream(__dirname + '/access.log',
                                             { flags: 'a' })
const app = new Koa()

// setup the logger
app.use(morgan('combined', { stream: accessLogStream }))

app.use((ctx) => {
  ctx.body = 'hello, world!'
})

app.listen(2333)

=0.x, working with koa-v1

var koa = require('koa');
var morgan = require('koa-morgan');
var app = koa();

app.use(morgan.middleware(format, options));