Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zhike/log-koa-middleware

Package Overview
Dependencies
Maintainers
11
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zhike/log-koa-middleware

日志打印中间件

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
11
Created
Source

log-koa-middleware

日志打印中间件

image

Install

$ npm install @zhike/log-koa-middleware

Example

const logger = require('@zhike/log-koa-middleware')
const Koa = require('koa')

const app = new Koa()

//只打印requestBody
app.use(logger())

// 打印所有路径的headers中的content-type。只打印以/player2开头的路径的responseBody
app.use(logger({
    requestHeaders: ['content-type'],
    responseHeaders: ['content-type'],
    responseBodyWhiteList: ['/^\/player2/']
}))

Configuration Options

参数名类型说明
reqIdString响应标识id(使用自定义的reqId需放在日志中间件前。如果为空且ctx.reqId为空则使用uuidv4自动生成reqId)
requestHeadersArray需要打印的request头部 (默认不打印)
responseHeadersArray需要打印的response头部 (默认不打印)
responseBodyWhiteListArray白名单,字符串数组,可为正则(对于正则匹配剔除部分路由,可在业务代码中的ctx.useResponseBodyOption=false跳过路由规则)
responseBodyBlackListArray黑名单,字符串数组,可为正则(对于正则匹配剔除部分路由,可在业务代码中使用ctx.useResponseBodyOption=false跳过路由规则)

注意:

  1. 必会打印reqId,路径,方法,响应时间。
  2. 默认打印requestBody。
  3. 默认不打印responseBody。
  4. responseBodyWhiteList和不能和responseBodyBlackList同时传值
  5. responseBodyWhiteList和responseBodyBlackList暂未支持同一path不同method,后续会完善。

Keywords

FAQs

Package last updated on 10 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc