npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vafast/request-logger

v0.3.4

Published

API request logging middleware for Vafast

Readme

@vafast/request-logger

API 请求日志中间件,将日志提交到远程日志服务。

安装

npm install @vafast/request-logger

使用

import { requestLogger } from '@vafast/request-logger'

server.use(requestLogger({
  url: 'http://log-server:9005/api/logs/ingest',
  service: 'my-service',
  headers: { Authorization: 'Bearer apiKeyId:apiKeySecret' },
  onError: (err) => console.error('日志记录失败', err),
}))

业务字段(appId、authType、ip、traceId 等)由日志服务端从 headers 自动解析。

配置

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | url | string | 是 | - | 日志服务 URL | | service | string | 是 | - | 服务标识 | | headers | Record<string, string> | 否 | {} | 自定义请求头(如认证) | | timeout | number | 否 | 5000 | 超时时间(毫秒) | | sanitize | SanitizeConfig | 否 | - | 敏感数据清洗配置 | | onError | (err) => void | 否 | console.error | 错误回调 | | enabled | boolean | 否 | true | 是否启用 |

路由级别控制

在路由定义中设置 log: false 跳过日志记录:

// 单个路由
{ method: 'GET', path: '/health', log: false, handler: ... }

// 父路由设置,子路由继承
{
  path: '/internal',
  log: false,
  children: [
    { method: 'GET', path: '/metrics', handler: ... },
    { method: 'GET', path: '/status', handler: ... },
  ]
}

日志数据格式

发送到日志服务的数据结构:

{
  method: 'POST',
  url: 'http://example.com/api/users?page=1',
  path: '/api/users',
  headers: { ... },
  body: { ... },
  query: { page: '1' },
  status: 200,
  duration: 50,
  service: 'my-service',
  userId: 'user123',
  appId: 'app456',
  authType: 'jwt',
  ip: '192.168.1.1',
  userAgent: 'Mozilla/5.0...',
  traceId: 'trace789',
  createdAt: '2024-01-01T00:00:00.000Z',
  response: {
    success: true,
    message: 'OK',
    code: 0,
  },
  responseData: { ... },
}

敏感数据脱敏

默认自动脱敏以下字段:

  • password, pwd, secret, token
  • authorization, cookie, x-api-key
  • accessToken, refreshToken, apiKey

自定义脱敏配置:

requestLogger({
  url: '...',
  service: '...',
  sanitize: {
    fields: ['password', 'creditCard', 'ssn'],
    mask: '******',
    deep: true,
  },
})

特性

  • 异步非阻塞(不影响响应速度)
  • 自动敏感数据脱敏
  • 路由级别日志控制
  • 支持多租户(appId)
  • 支持分布式追踪(traceId)