Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

koa-logger

koajs1.5mMIT3.2.1TypeScript support: definitely-typed

Logging middleware for koa

koa, middleware, logger, log

readme

koa-logger

npm version build status

Development style logger middleware for koa. Compatible with request-received.

Notice: koa-logger@2 supports koa@2; if you want to use this module with koa@1, please use koa-logger@1.

<-- GET /
--> GET / 200 835ms 746b
<-- GET /
--> GET / 200 960ms 1.9kb
<-- GET /users
--> GET /users 200 357ms 922b
<-- GET /users?page=2
--> GET /users?page=2 200 466ms 4.66kb

Installation

$ npm install koa-logger

Example

const logger = require('koa-logger')
const Koa = require('koa')

const app = new Koa()
app.use(logger())

Notes

Recommended that you .use() this middleware near the top to "wrap" all subsequent middleware.

Use Custom Transporter

const logger = require('koa-logger')
const Koa = require('koa')

const app = new Koa()
app.use(logger((str, args) => {
  // redirect koa logger to other output pipe
  // default is process.stdout(by console.log function)
}))

or

app.use(logger({
  transporter: (str, args) => {
    // ...
  }
}))

Param str is output string with ANSI Color, and you can get pure text with other modules like strip-ansi
Param args is a array by [format, method, url, status, time, length]

License

MIT

changelog

3.2.0 / 2018-03-13

  • add a transporter to logger opts param (#65)

3.1.0 / 2017-09-26

  • Adds Boom compatibility (#64)

3.0.1 / 2017-06-30

  • Fixes error 'chalk[color] does not return function' when using custom (#61)

3.0.0 / 2017-05-16

  • use async function
  • update bytes to 2.x

2.0.1 / 2017-01-12

  • add color for code 0
  • bump deps

2.0.0 / 2015-11-19

  • add: support for koa 2
  • remove: support for koa 1

1.2.2 / 2014-07-05

  • fix: stop using octal literals for strict mode

1.2.1 / 2014-05-13

  • bump bytes

1.2.0 / 2014-02-12

  • add: add colors and symbols for error and close events
  • remove: only make the method bold

1.1.1 / 2014-01-15

  • fix: use ctx.originalUrl instead of ctx.url

1.1.0 / 2013-12-21

  • add: log the response length of streams
  • add: humanize the response time
  • add: log when response is finished/closed, not caught upstream

1.0.1 / 2013-08-22

  • fix exception handling