koa-format-logger

3.2.0 • Public • Published

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

Package Sidebar

Install

npm i koa-format-logger

Weekly Downloads

0

Version

3.2.0

License

MIT

Unpacked Size

7.07 kB

Total Files

4

Last publish

Collaborators

  • laumlin