@jeson.xk/koa-logger
v4.1.2
Published
Logging middleware for koa (forked from koajs/logger)
Readme
Koa logger is unmanned, and this project has been optimized based on Koa logger. The following adjustments have been made:
- pass ctx to transpoter. Please see Transporter below for usage instructions
koa-logger
Development style logger middleware for koa. Compatible with request-received.
<-- 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.66kbInstallation
$ npm i @jeson.xk/koa-loggerExample
const logger = require('@jeson.xk/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('@jeson.xk/koa-logger')
const Koa = require('koa')
const app = new Koa()
app.use(logger((str, args, ctx) => {
// redirect koa logger to other output pipe
// default is process.stdout(by console.log function)
}))or
app.use(logger({
transporter: (str, args, ctx) => {
// ...
}
}))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]
Param ctx is the app context
License
MIT
