mowatermelon / learn-es6

一个有趣的人写的有趣的前端基础
http://blog.iiwhy.cn/learn-es6
7 stars 5 forks source link

npm-koa-logger #113

Open mowatermelon opened 4 years ago

mowatermelon commented 4 years ago

koa-logger

官方仓库

https://github.com/koajs/logger

官方npm地址

依赖包地址

https://www.npmjs.com/package/koa-logger

image

在线运行地址

https://npm.runkit.com/koa-logger

基础介绍

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

基础安装

npm install koa-logger --save   # npm
yarn add koa-logger            # Yarn

基础使用

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

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]