3.2.0 • Published 6 years ago

koa-format-logger v3.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

koa-logger

  <-- req  GET /dist/web.app.js 2018-10-29 20:51:05
  --> res  GET /dist/web.app.js 200 3ms 10.26mb
  <-- req  GET /dist/web.27.js 2018-10-29 20:51:05
  --> res  GET /dist/web.27.js 200 1ms 29.82kb
  <-- req  GET /dist/web.57.js 2018-10-29 20:51:05
  --> res  GET /dist/web.57.js 200 2ms 36.16kb

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